Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ vendor/
.phpunit.result.cache
.php-cs-fixer.cache
phpunit.xml
.vscode/
.vscode/
phpstan.neon
36 changes: 0 additions & 36 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,47 +1,11 @@
parameters:
ignoreErrors:
-
message: '#^Call to an undefined method FeedIo\\Feed\\ItemInterface\:\:setHostInContent\(\)\.$#'
identifier: method.notFound
count: 1
path: src/FeedIo/Feed.php

-
message: '#^Call to an undefined method FeedIo\\Feed\\ItemInterface\:\:setLinkForAnalysis\(\)\.$#'
identifier: method.notFound
count: 1
path: src/FeedIo/Parser/XmlParser.php

-
message: '#^Deprecated in PHP 8\.0\: Required parameter \$url follows optional parameter \$modifiedSince\.$#'
identifier: parameter.requiredAfterOptional
count: 1
path: src/FeedIo/Reader/Result.php

-
message: '#^Deprecated in PHP 8\.1\: Required parameter \$response follows optional parameter \$modifiedSince\.$#'
identifier: parameter.requiredAfterOptional
count: 1
path: src/FeedIo/Reader/Result.php

-
message: '#^Offset float on list in isset\(\) does not exist\.$#'
identifier: isset.offset
count: 1
path: src/FeedIo/Reader/Result/UpdateStats.php

-
message: '#^Call to an undefined method FeedIo\\Feed\\NodeInterface\:\:getHostFromLink\(\)\.$#'
identifier: method.notFound
count: 1
path: src/FeedIo/Rule/Atom/Link.php

-
message: '#^Call to an undefined method FeedIo\\Feed\\NodeInterface\:\:getHostFromLink\(\)\.$#'
identifier: method.notFound
count: 1
path: src/FeedIo/Rule/Link.php

-
message: '#^PHPDoc tag @var with type FeedIo\\Reader\\FixerAbstract is not subtype of native type FeedIo\\Reader\\Fixer\\HttpLastModified\|FeedIo\\Reader\\Fixer\\PublicId\.$#'
identifier: varTag.nativeType
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Rector\Config\RectorConfig;
use Rector\Php84\Rector\Param\ExplicitNullableParamTypeRector;
use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
Expand All @@ -13,4 +14,5 @@
->withPhpVersion(PhpVersion::PHP_84)
->withRules([
ExplicitNullableParamTypeRector::class,
OptionalParametersAfterRequiredRector::class,
]);
6 changes: 4 additions & 2 deletions src/FeedIo/Feed/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ protected function setHost(?string $link = null): void
}
}

protected function setHostInContent(?string $host = null): void
public function setHostInContent(?string $host = null): NodeInterface
{
if (is_null($host)) {
return;
return $this;
}
// Replaced links like href="/aaa/bbb.xxx"
$pattern = '(<\s*[^>]*)(href=|src=)(.?)(\/[^\/])(?!(.(?!<code))*<\/code>)';
Expand All @@ -187,6 +187,8 @@ protected function setHostInContent(?string $host = null): void
$pattern = '(<\s*[^>]*)(href=|src=)(.?)(\w+\b)(?![:])(?!(.(?!<code))*<\/code>)';
$this->pregReplaceInProperty('content', $pattern, '\1\2\3'.$itemLink.'\4');
$this->pregReplaceInProperty('description', $pattern, '\1\2\3'.$itemLink.'\4');

return $this;
}

public function pregReplaceInProperty(string $property, string $pattern, string $replacement): void
Expand Down
30 changes: 30 additions & 0 deletions src/FeedIo/Feed/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,34 @@ public function getValue(string $name): ?string;
* @return NodeInterface
*/
public function set(string $name, ?string $value = null): NodeInterface;

/**
* Sets the host in content
*
* @param string|null $host
* @return NodeInterface
*/
public function setHostInContent(?string $host = null): NodeInterface;

/**
* Gets the host from link
*
* @return string|null
*/
public function getHostFromLink(): ?string;

/**
* Sets the link for analysis
*
* @param string|null $link
* @return NodeInterface
*/
public function setLinkForAnalysis(?string $link = null): NodeInterface;

/**
* Gets the link for analysis
*
* @return string|null
*/
public function getLinkForAnalysis(): ?string;
}
2 changes: 1 addition & 1 deletion src/FeedIo/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function read(string $url, FeedInterface $feed, ?DateTime $modifiedSince
$feed->setLink($url);
$document = $this->handleResponse($response, $feed);

return new Result($document, $feed, $modifiedSince, $response, $url);
return new Result($document, $feed, $response, $url, $modifiedSince);
} catch (\Exception $e) {
$this->logger->warning("{$url} read error : {$e->getMessage()}");
throw new ReadErrorException($e->getMessage(), $e->getCode(), $e);
Expand Down
4 changes: 2 additions & 2 deletions src/FeedIo/Reader/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Result
public function __construct(
protected Document $document,
protected FeedInterface $feed,
protected ?DateTime $modifiedSince = null,
protected ResponseInterface $response,
protected string $url
protected string $url,
protected ?DateTime $modifiedSince = null
) {
$this->date = new DateTime();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FeedIo/Reader/ResultMockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function makeWithFeed(Feed $feed): Result
/** @var ResponseInterface $response */
$response = new NullResponse();

return new Result($document, $feed, new \DateTime('@0'), $response, 'http://localhost/test.rss');
return new Result($document, $feed, $response, 'http://localhost/test.rss', new \DateTime('@0'));
}
}
4 changes: 2 additions & 2 deletions tests/FeedIo/Reader/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ protected function setUp(): void
$this->object = new Result(
new Document('<feed></feed>'),
new Feed(),
$this->modifiedSince,
$response,
'http://localhost'
'http://localhost',
$this->modifiedSince
);
}

Expand Down