From ba3e4d962e9fc9b5a76c5107dc7af3ac47af7057 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 13 Aug 2025 20:26:24 +0200 Subject: [PATCH 1/3] Fixed Optional Parameters After Required --- rector.php | 2 ++ src/FeedIo/Reader.php | 2 +- src/FeedIo/Reader/Result.php | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/rector.php b/rector.php index 2bb5054d..41f019c5 100644 --- a/rector.php +++ b/rector.php @@ -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() @@ -13,4 +14,5 @@ ->withPhpVersion(PhpVersion::PHP_84) ->withRules([ ExplicitNullableParamTypeRector::class, + OptionalParametersAfterRequiredRector::class, ]); diff --git a/src/FeedIo/Reader.php b/src/FeedIo/Reader.php index 174f65cb..b60fad8b 100644 --- a/src/FeedIo/Reader.php +++ b/src/FeedIo/Reader.php @@ -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); diff --git a/src/FeedIo/Reader/Result.php b/src/FeedIo/Reader/Result.php index c9be2db1..267d8edd 100644 --- a/src/FeedIo/Reader/Result.php +++ b/src/FeedIo/Reader/Result.php @@ -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(); } From 19e73e76c519916066618275748675c3c505abc9 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 13 Aug 2025 21:35:34 +0200 Subject: [PATCH 2/3] Fixed Call to an undefined method --- .gitignore | 3 ++- phpstan-baseline.neon | 36 ------------------------------- src/FeedIo/Feed/Node.php | 6 ++++-- src/FeedIo/Feed/NodeInterface.php | 30 ++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 8d732ea1..9eb7b2db 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ vendor/ .phpunit.result.cache .php-cs-fixer.cache phpunit.xml -.vscode/ \ No newline at end of file +.vscode/ +phpstan.neon \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c968ee54..3f4977f3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/src/FeedIo/Feed/Node.php b/src/FeedIo/Feed/Node.php index 87a01d22..227c341c 100644 --- a/src/FeedIo/Feed/Node.php +++ b/src/FeedIo/Feed/Node.php @@ -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=)(.?)(\/[^\/])(?!(.(?!)'; @@ -187,6 +187,8 @@ protected function setHostInContent(?string $host = null): void $pattern = '(<\s*[^>]*)(href=|src=)(.?)(\w+\b)(?![:])(?!(.(?!)'; $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 diff --git a/src/FeedIo/Feed/NodeInterface.php b/src/FeedIo/Feed/NodeInterface.php index d4c6715a..5d94bfbe 100644 --- a/src/FeedIo/Feed/NodeInterface.php +++ b/src/FeedIo/Feed/NodeInterface.php @@ -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; } From 78a6c4a3bad66f968609cf715dfb5cd6a78bd377 Mon Sep 17 00:00:00 2001 From: Benjamin Brahmer Date: Wed, 13 Aug 2025 21:42:47 +0200 Subject: [PATCH 3/3] Fix failing tests --- tests/FeedIo/Reader/ResultMockFactory.php | 2 +- tests/FeedIo/Reader/ResultTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/FeedIo/Reader/ResultMockFactory.php b/tests/FeedIo/Reader/ResultMockFactory.php index 04e2dbf2..03d74510 100644 --- a/tests/FeedIo/Reader/ResultMockFactory.php +++ b/tests/FeedIo/Reader/ResultMockFactory.php @@ -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')); } } diff --git a/tests/FeedIo/Reader/ResultTest.php b/tests/FeedIo/Reader/ResultTest.php index 9cb0e952..5aad88c0 100644 --- a/tests/FeedIo/Reader/ResultTest.php +++ b/tests/FeedIo/Reader/ResultTest.php @@ -35,9 +35,9 @@ protected function setUp(): void $this->object = new Result( new Document(''), new Feed(), - $this->modifiedSince, $response, - 'http://localhost' + 'http://localhost', + $this->modifiedSince ); }