Skip to content

Commit

Permalink
Fix PHPStan deprecations (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored Oct 8, 2024
1 parent 7a7de3d commit 5684174
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
includes:
- extension.neon
- ignore-by-php-version.neon.php
- phar://phpstan.phar/conf/bleedingEdge.neon

parameters:
level: 8
Expand Down
11 changes: 6 additions & 5 deletions src/TodoByPackageVersionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,7 +52,7 @@ final class TodoByPackageVersionRule implements Rule
private string $workingDirectory;

/**
* @var null|string|RuleError
* @var null|string|IdentifierRuleError
*/
private $phpPlatformVersion;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 5 additions & 4 deletions src/TodoBySymfonyDeprecationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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();
}
}
}
1 change: 1 addition & 0 deletions src/TodoByVersionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
Expand Down
1 change: 0 additions & 1 deletion src/utils/CommentMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down
6 changes: 3 additions & 3 deletions src/utils/ExpiredCommentErrorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function buildError(
string $errorIdentifier,
?string $tip,
int $wholeMatchStartOffset
): \PHPStan\Rules\RuleError {
): \PHPStan\Rules\IdentifierRuleError {
return $this->build(
$comment,
$startLine,
Expand All @@ -45,7 +45,7 @@ public function buildFileError(
int $wholeMatchStartOffset,
string $file,
int $line
): \PHPStan\Rules\RuleError {
): \PHPStan\Rules\IdentifierRuleError {
return $this->build(
$comment,
$startLine,
Expand All @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/utils/GitTagFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
}
}
2 changes: 1 addition & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 5684174

Please sign in to comment.