diff --git a/phpstan.neon b/phpstan.neon index ddcc1f5..306d399 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,7 @@ includes: - extension.neon - ignore-by-php-version.neon.php + - phar://phpstan.phar/conf/bleedingEdge.neon parameters: level: 8 diff --git a/src/TodoByPackageVersionRule.php b/src/TodoByPackageVersionRule.php index e410de8..3711fa3 100644 --- a/src/TodoByPackageVersionRule.php +++ b/src/TodoByPackageVersionRule.php @@ -9,6 +9,7 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Internal\ComposerHelper; +use PHPStan\Rules\IdentifierRuleError; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleError; use staabm\PHPStanTodoBy\utils\CommentMatcher; @@ -51,7 +52,7 @@ final class TodoByPackageVersionRule implements Rule private string $workingDirectory; /** - * @var null|string|RuleError + * @var null|string|IdentifierRuleError */ private $phpPlatformVersion; @@ -139,7 +140,7 @@ public function processNode(Node $node, Scope $scope): array } /** - * @return bool|RuleError + * @return bool|IdentifierRuleError */ private function satisfiesPhpPlatformPackage(string $package, string $version, Comment $comment, int $wholeMatchStartOffset) { @@ -168,7 +169,7 @@ private function satisfiesPhpPlatformPackage(string $package, string $version, C } /** - * @return bool|RuleError + * @return bool|IdentifierRuleError */ private function satisfiesVirtualPackage(string $package, string $version, Comment $comment, int $wholeMatchStartOffset) { @@ -205,7 +206,7 @@ private function satisfiesVirtualPackage(string $package, string $version, Comme } /** - * @return RuleError|string + * @return IdentifierRuleError|string */ private function readPhpPlatformVersion(Comment $comment, int $wholeMatchStartOffset) { @@ -253,7 +254,7 @@ private function readPhpPlatformVersion(Comment $comment, int $wholeMatchStartOf } /** - * @return bool|RuleError + * @return bool|IdentifierRuleError */ private function satisfiesInstalledPackage(string $package, string $version, Comment $comment, int $wholeMatchStartOffset) { diff --git a/src/TodoBySymfonyDeprecationRule.php b/src/TodoBySymfonyDeprecationRule.php index 230b16d..f59e142 100644 --- a/src/TodoBySymfonyDeprecationRule.php +++ b/src/TodoBySymfonyDeprecationRule.php @@ -6,6 +6,7 @@ use Composer\Semver\VersionParser; use PhpParser\Node; use PHPStan\Analyser\Scope; +use PHPStan\Rules\IdentifierRuleError; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleError; use PHPStan\Rules\RuleErrorBuilder; @@ -90,7 +91,7 @@ public function processNode(Node $node, Scope $scope): array } /** - * @return bool|RuleError + * @return bool|IdentifierRuleError */ private function satisfiesInstalledPackage(string $package, string $version) { @@ -104,9 +105,9 @@ private function satisfiesInstalledPackage(string $package, string $version) try { return InstalledVersions::satisfies($versionParser, $package, '>='.$version); } catch (UnexpectedValueException $e) { - return RuleErrorBuilder::message( - 'Invalid version constraint "' . $version . '" for package "' . $package . '".', - )->build(); + return RuleErrorBuilder::message('Invalid version constraint "' . $version . '" for package "' . $package . '".') + ->identifier(ExpiredCommentErrorBuilder::ERROR_IDENTIFIER_PREFIX.self::ERROR_IDENTIFIER) + ->build(); } } } diff --git a/src/TodoByVersionRule.php b/src/TodoByVersionRule.php index 8f310f3..73f972e 100644 --- a/src/TodoByVersionRule.php +++ b/src/TodoByVersionRule.php @@ -79,6 +79,7 @@ public function processNode(Node $node, Scope $scope): array return [ RuleErrorBuilder::message($e->getMessage()) ->tip('See https://github.com/staabm/phpstan-todo-by#could-not-determine-latest-git-tag-error') + ->identifier(ExpiredCommentErrorBuilder::ERROR_IDENTIFIER_PREFIX.self::ERROR_IDENTIFIER) ->build(), ]; } diff --git a/src/utils/CommentMatcher.php b/src/utils/CommentMatcher.php index 99e4f7f..2e3725a 100644 --- a/src/utils/CommentMatcher.php +++ b/src/utils/CommentMatcher.php @@ -20,7 +20,6 @@ public static function matchComments(Node $node, string $pattern): iterable $node instanceof Node\Stmt\InlineHTML || $node instanceof Node\Name || $node instanceof Node\Identifier - || $node instanceof \PHPStan\Node\CollectedDataNode // see https://github.com/phpstan/phpstan/discussions/11701 ) { // prevent unnecessary work / reduce memory consumption return []; diff --git a/src/utils/ExpiredCommentErrorBuilder.php b/src/utils/ExpiredCommentErrorBuilder.php index 54f040a..4183b05 100644 --- a/src/utils/ExpiredCommentErrorBuilder.php +++ b/src/utils/ExpiredCommentErrorBuilder.php @@ -23,7 +23,7 @@ public function buildError( string $errorIdentifier, ?string $tip, int $wholeMatchStartOffset - ): \PHPStan\Rules\RuleError { + ): \PHPStan\Rules\IdentifierRuleError { return $this->build( $comment, $startLine, @@ -45,7 +45,7 @@ public function buildFileError( int $wholeMatchStartOffset, string $file, int $line - ): \PHPStan\Rules\RuleError { + ): \PHPStan\Rules\IdentifierRuleError { return $this->build( $comment, $startLine, @@ -67,7 +67,7 @@ private function build( int $wholeMatchStartOffset, ?string $file, ?int $line - ): \PHPStan\Rules\RuleError { + ): \PHPStan\Rules\IdentifierRuleError { // Count the number of newlines between the start of the whole comment, and the start of the match. $newLines = substr_count($comment, "\n", 0, $wholeMatchStartOffset); diff --git a/src/utils/GitTagFetcher.php b/src/utils/GitTagFetcher.php index 107065d..49b2f59 100644 --- a/src/utils/GitTagFetcher.php +++ b/src/utils/GitTagFetcher.php @@ -7,7 +7,7 @@ final class GitTagFetcher implements TagFetcher { // fetch version of the latest created git tag - public function fetchLatestTagVersion(?string $workingDirectory): ?string + public function fetchLatestTagVersion(?string $workingDirectory): string { // requires tags have been fetched into the local clone // see https://github.com/staabm/phpstan-todo-by#reference-version @@ -26,7 +26,6 @@ public function fetchLatestTagVersion(?string $workingDirectory): ?string throw new LatestTagNotFoundException('Could not determine latest git tag'); } - // a repo might not contain any tags - return $output[0] ?? null; + return $output[0]; } } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 7e3937a..963b934 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -36,7 +36,7 @@ private function runAnalyse(string $file): array { $file = $this->getFileHelper()->normalizePath($file); /** @var Analyser $analyser */ - $analyser = self::getContainer()->getByType(Analyser::class); + $analyser = self::getContainer()->getByType(Analyser::class); /** @phpstan-ignore phpstanApi.classConstant */ /** @var FileHelper $fileHelper */ $fileHelper = self::getContainer()->getByType(FileHelper::class); /** @phpstan-ignore-next-line missing bc promise */