From cfdeb254c269006c5774430d3dda4de849916100 Mon Sep 17 00:00:00 2001 From: Martin Lutonsky Date: Fri, 5 Dec 2025 17:38:27 +0100 Subject: [PATCH 1/5] Add failing unit test for TodoByVersionRule for "testing" tag --- ...odoByVersionRuleTestingTagFetchterTest.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/TodoByVersionRuleTestingTagFetchterTest.php diff --git a/tests/TodoByVersionRuleTestingTagFetchterTest.php b/tests/TodoByVersionRuleTestingTagFetchterTest.php new file mode 100644 index 0000000..f250fa7 --- /dev/null +++ b/tests/TodoByVersionRuleTestingTagFetchterTest.php @@ -0,0 +1,34 @@ + + * @internal + */ +final class TodoByVersionRuleTestingTagFetchterTest extends RuleTestCase +{ + private string $referenceVersion; + + protected function getRule(): Rule + { + return new TodoByVersionRule( + true, + new ReferenceVersionFinder($this->referenceVersion, new StaticTagFetcher('testing')), + new ExpiredCommentErrorBuilder(true) + ); + } + + public function testNoTagIsFetched(): void + { + $this->referenceVersion = 'nextMajor'; + + $this->analyse([__DIR__ . '/data/tagNotFound.php'], []); + } +} From 4789704e85d498e8933ca0ae78c092aed89624c0 Mon Sep 17 00:00:00 2001 From: Martin Lutonsky Date: Fri, 5 Dec 2025 18:09:55 +0100 Subject: [PATCH 2/5] TodoByVersionRule - handle invalid version tag --- src/TodoByVersionRule.php | 7 +++++++ src/utils/InvalidTagException.php | 9 +++++++++ src/utils/ReferenceVersionFinder.php | 10 ++++++++-- tests/TodoByVersionRuleTestingTagFetchterTest.php | 7 ++++++- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/utils/InvalidTagException.php diff --git a/src/TodoByVersionRule.php b/src/TodoByVersionRule.php index 73f972e..d19c824 100644 --- a/src/TodoByVersionRule.php +++ b/src/TodoByVersionRule.php @@ -9,6 +9,7 @@ use PHPStan\Rules\RuleErrorBuilder; use staabm\PHPStanTodoBy\utils\CommentMatcher; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; +use staabm\PHPStanTodoBy\utils\InvalidTagException; use staabm\PHPStanTodoBy\utils\LatestTagNotFoundException; use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; use UnexpectedValueException; @@ -82,6 +83,12 @@ public function processNode(Node $node, Scope $scope): array ->identifier(ExpiredCommentErrorBuilder::ERROR_IDENTIFIER_PREFIX.self::ERROR_IDENTIFIER) ->build(), ]; + } catch (InvalidTagException $e) { + return [ + RuleErrorBuilder::message($e->getMessage()) + ->identifier(ExpiredCommentErrorBuilder::ERROR_IDENTIFIER_PREFIX.self::ERROR_IDENTIFIER) + ->build(), + ]; } $provided = $versionParser->parseConstraints( $referenceVersion diff --git a/src/utils/InvalidTagException.php b/src/utils/InvalidTagException.php new file mode 100644 index 0000000..6d5a50c --- /dev/null +++ b/src/utils/InvalidTagException.php @@ -0,0 +1,9 @@ +referenceVersion = 'nextMajor'; - $this->analyse([__DIR__ . '/data/tagNotFound.php'], []); + $this->analyse([__DIR__ . '/data/tagNotFound.php'], [ + [ + "Could not parse version from tag 'testing'", + 5, + ], + ]); } } From 5c76247a8e09bc4f202e8e0f609e78192767658c Mon Sep 17 00:00:00 2001 From: Martin Lutonsky Date: Fri, 5 Dec 2025 18:10:37 +0100 Subject: [PATCH 3/5] fixed codestyle --- src/TodoByVersionRule.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/TodoByVersionRule.php b/src/TodoByVersionRule.php index d19c824..6411cc5 100644 --- a/src/TodoByVersionRule.php +++ b/src/TodoByVersionRule.php @@ -101,7 +101,7 @@ public function processNode(Node $node, Scope $scope): array // assume a min version constraint, when the comment does not specify a comparator if (null === $this->getVersionComparator($version)) { - $version = '>='. $version; + $version = '>=' . $version; } try { @@ -125,7 +125,7 @@ public function processNode(Node $node, Scope $scope): array // If there is further text, append it. if ('' !== $todoText) { - $errorMessage = "Version requirement {$version} satisfied: ". rtrim($todoText, '.') .'.'; + $errorMessage = "Version requirement {$version} satisfied: " . rtrim($todoText, '.') . '.'; } else { $errorMessage = "Version requirement {$version} satisfied."; } @@ -135,7 +135,7 @@ public function processNode(Node $node, Scope $scope): array $comment->getStartLine(), $errorMessage, self::ERROR_IDENTIFIER, - "Calculated reference version is '". $referenceVersion ."'.\n\n See also:\n https://github.com/staabm/phpstan-todo-by#reference-version", + "Calculated reference version is '" . $referenceVersion . "'.\n\n See also:\n https://github.com/staabm/phpstan-todo-by#reference-version", $match[0][1] ); } From 5c08ec8256566b984479951a12c87baa7834a888 Mon Sep 17 00:00:00 2001 From: Martin Lutonsky Date: Fri, 5 Dec 2025 18:35:00 +0100 Subject: [PATCH 4/5] Renamend test case for better semantic --- ...FetchterTest.php => TodoByVersionRuleNonSemverTagTest.php} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename tests/{TodoByVersionRuleTestingTagFetchterTest.php => TodoByVersionRuleNonSemverTagTest.php} (88%) diff --git a/tests/TodoByVersionRuleTestingTagFetchterTest.php b/tests/TodoByVersionRuleNonSemverTagTest.php similarity index 88% rename from tests/TodoByVersionRuleTestingTagFetchterTest.php rename to tests/TodoByVersionRuleNonSemverTagTest.php index 494b91c..c50bd0f 100644 --- a/tests/TodoByVersionRuleTestingTagFetchterTest.php +++ b/tests/TodoByVersionRuleNonSemverTagTest.php @@ -12,7 +12,7 @@ * @extends RuleTestCase * @internal */ -final class TodoByVersionRuleTestingTagFetchterTest extends RuleTestCase +final class TodoByVersionRuleNonSemverTagTest extends RuleTestCase { private string $referenceVersion; @@ -25,7 +25,7 @@ protected function getRule(): Rule ); } - public function testNoTagIsFetched(): void + public function testInvalidTagIsParsed(): void { $this->referenceVersion = 'nextMajor'; From 4fc5ea298556427f151cce08f8543bc70d501289 Mon Sep 17 00:00:00 2001 From: Martin Lutonsky Date: Fri, 5 Dec 2025 18:35:58 +0100 Subject: [PATCH 5/5] ReferenceVersionFinder - use instance method call instead of static one --- src/utils/ReferenceVersionFinder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ReferenceVersionFinder.php b/src/utils/ReferenceVersionFinder.php index 3f4ae5e..ae3bff4 100644 --- a/src/utils/ReferenceVersionFinder.php +++ b/src/utils/ReferenceVersionFinder.php @@ -57,7 +57,7 @@ private function nextVersion(string $versionString, ?string $originalVersionStri } try { - return self::nextVersion($versionString, $originalVersionString); + return $this->nextVersion($versionString, $originalVersionString); } catch (InvalidVersionString $invalidVersionException) { throw new InvalidTagException("Could not parse version from tag '{$originalVersionString}'", 0, $invalidVersionException); }