diff --git a/extension.neon b/extension.neon index 9c368f4..2099e18 100644 --- a/extension.neon +++ b/extension.neon @@ -48,9 +48,6 @@ services: arguments: - %todo_by.referenceVersion% - - - class: staabm\PHPStanTodoBy\utils\VersionNormalizer - - class: staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder arguments: diff --git a/src/TodoByDateRule.php b/src/TodoByDateRule.php index 6987cd4..55fa18d 100644 --- a/src/TodoByDateRule.php +++ b/src/TodoByDateRule.php @@ -4,19 +4,11 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; -use PHPStan\Node\VirtualNode; use PHPStan\Rules\Rule; -use PHPStan\Rules\RuleErrorBuilder; -use PHPStan\ShouldNotHappenException; use staabm\PHPStanTodoBy\utils\CommentMatcher; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; -use function preg_match_all; use function strtotime; -use function substr_count; -use function time; use function trim; -use const PREG_OFFSET_CAPTURE; -use const PREG_SET_ORDER; /** * @implements Rule diff --git a/src/TodoByPackageVersionRule.php b/src/TodoByPackageVersionRule.php index 47e2778..a4cb141 100644 --- a/src/TodoByPackageVersionRule.php +++ b/src/TodoByPackageVersionRule.php @@ -16,7 +16,6 @@ use staabm\PHPStanTodoBy\utils\CommentMatcher; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; -use staabm\PHPStanTodoBy\utils\VersionNormalizer; use function preg_match_all; use function substr_count; use function trim; diff --git a/src/TodoByVersionRule.php b/src/TodoByVersionRule.php index abc0e01..2ca4186 100644 --- a/src/TodoByVersionRule.php +++ b/src/TodoByVersionRule.php @@ -2,22 +2,14 @@ namespace staabm\PHPStanTodoBy; -use Composer\Semver\Comparator; use Composer\Semver\VersionParser; use PhpParser\Node; use PHPStan\Analyser\Scope; -use PHPStan\Node\VirtualNode; use PHPStan\Rules\Rule; -use PHPStan\Rules\RuleErrorBuilder; use staabm\PHPStanTodoBy\utils\CommentMatcher; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; -use staabm\PHPStanTodoBy\utils\VersionNormalizer; -use function preg_match_all; -use function substr_count; use function trim; -use const PREG_OFFSET_CAPTURE; -use const PREG_SET_ORDER; /** * @implements Rule @@ -38,8 +30,6 @@ final class TodoByVersionRule implements Rule }ix REGEXP; - private VersionNormalizer $versionNormalizer; - private ReferenceVersionFinder $referenceVersionFinder; private bool $singleGitRepo; @@ -54,13 +44,11 @@ final class TodoByVersionRule implements Rule public function __construct( bool $singleGitRepo, ReferenceVersionFinder $refVersionFinder, - VersionNormalizer $versionNormalizer, ExpiredCommentErrorBuilder $errorBuilder ) { $this->referenceVersionFinder = $refVersionFinder; $this->errorBuilder = $errorBuilder; $this->singleGitRepo = $singleGitRepo; - $this->versionNormalizer = $versionNormalizer; } public function getNodeType(): string @@ -140,8 +128,9 @@ private function getReferenceVersion(Scope $scope): string } if (!array_key_exists($cacheKey, $this->referenceVersions)) { + $versionParser = new VersionParser(); // lazy get the version, as it might incur subprocess creation - $this->referenceVersions[$cacheKey] = $this->versionNormalizer->normalize( + $this->referenceVersions[$cacheKey] = $versionParser->normalize( $this->referenceVersionFinder->find($workingDirectory) ); } diff --git a/src/utils/VersionNormalizer.php b/src/utils/VersionNormalizer.php deleted file mode 100644 index b0a60ca..0000000 --- a/src/utils/VersionNormalizer.php +++ /dev/null @@ -1,20 +0,0 @@ -versionParser = new VersionParser(); - } - - public function normalize(string $version): string - { - return $this->versionParser->normalize($version); - } -} diff --git a/tests/TodoByPackageVersionRuleTest.php b/tests/TodoByPackageVersionRuleTest.php index ac33e73..849e132 100644 --- a/tests/TodoByPackageVersionRuleTest.php +++ b/tests/TodoByPackageVersionRuleTest.php @@ -5,11 +5,7 @@ use PHPStan\Rules\Rule; use PHPStan\Testing\RuleTestCase; use staabm\PHPStanTodoBy\TodoByPackageVersionRule; -use staabm\PHPStanTodoBy\TodoByVersionRule; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; -use staabm\PHPStanTodoBy\utils\GitTagFetcher; -use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; -use staabm\PHPStanTodoBy\utils\VersionNormalizer; /** * @extends RuleTestCase diff --git a/tests/TodoByVersionRuleAlwaysThrowingFetchterTest.php b/tests/TodoByVersionRuleAlwaysThrowingFetchterTest.php index af469d4..00670d0 100644 --- a/tests/TodoByVersionRuleAlwaysThrowingFetchterTest.php +++ b/tests/TodoByVersionRuleAlwaysThrowingFetchterTest.php @@ -7,7 +7,6 @@ use staabm\PHPStanTodoBy\TodoByVersionRule; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; -use staabm\PHPStanTodoBy\utils\VersionNormalizer; /** * @extends RuleTestCase @@ -20,7 +19,6 @@ protected function getRule(): Rule return new TodoByVersionRule( true, new ReferenceVersionFinder($this->referenceVersion, new AlwaysThrowingTagFetcher()), - new VersionNormalizer(), new ExpiredCommentErrorBuilder(true) ); } diff --git a/tests/TodoByVersionRuleSingleTimeFetchterTest.php b/tests/TodoByVersionRuleSingleTimeFetchterTest.php index db6a663..ef88338 100644 --- a/tests/TodoByVersionRuleSingleTimeFetchterTest.php +++ b/tests/TodoByVersionRuleSingleTimeFetchterTest.php @@ -7,7 +7,6 @@ use staabm\PHPStanTodoBy\TodoByVersionRule; use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; -use staabm\PHPStanTodoBy\utils\VersionNormalizer; /** * @extends RuleTestCase @@ -20,7 +19,6 @@ protected function getRule(): Rule return new TodoByVersionRule( false, new ReferenceVersionFinder($this->referenceVersion, new SingleTimeTagFetcher()), - new VersionNormalizer(), new ExpiredCommentErrorBuilder(true) ); } diff --git a/tests/TodoByVersionRuleTest.php b/tests/TodoByVersionRuleTest.php index a1e94a4..969ccc3 100644 --- a/tests/TodoByVersionRuleTest.php +++ b/tests/TodoByVersionRuleTest.php @@ -8,7 +8,6 @@ use staabm\PHPStanTodoBy\utils\ExpiredCommentErrorBuilder; use staabm\PHPStanTodoBy\utils\GitTagFetcher; use staabm\PHPStanTodoBy\utils\ReferenceVersionFinder; -use staabm\PHPStanTodoBy\utils\VersionNormalizer; /** * @extends RuleTestCase @@ -21,7 +20,6 @@ protected function getRule(): Rule return new TodoByVersionRule( true, new ReferenceVersionFinder($this->referenceVersion, new GitTagFetcher()), - new VersionNormalizer(), new ExpiredCommentErrorBuilder(true), ); }