Skip to content

Commit b32854a

Browse files
committed
Fix PHPStan deprecations
1 parent 8b432ef commit b32854a

File tree

8 files changed

+19
-17
lines changed

8 files changed

+19
-17
lines changed

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
includes:
22
- extension.neon
33
- ignore-by-php-version.neon.php
4+
- phar://phpstan.phar/conf/bleedingEdge.neon
45

56
parameters:
67
level: 8

src/TodoByPackageVersionRule.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node;
1010
use PHPStan\Analyser\Scope;
1111
use PHPStan\Internal\ComposerHelper;
12+
use PHPStan\Rules\IdentifierRuleError;
1213
use PHPStan\Rules\Rule;
1314
use PHPStan\Rules\RuleError;
1415
use staabm\PHPStanTodoBy\utils\CommentMatcher;
@@ -51,7 +52,7 @@ final class TodoByPackageVersionRule implements Rule
5152
private string $workingDirectory;
5253

5354
/**
54-
* @var null|string|RuleError
55+
* @var null|string|IdentifierRuleError
5556
*/
5657
private $phpPlatformVersion;
5758

@@ -139,7 +140,7 @@ public function processNode(Node $node, Scope $scope): array
139140
}
140141

141142
/**
142-
* @return bool|RuleError
143+
* @return bool|IdentifierRuleError
143144
*/
144145
private function satisfiesPhpPlatformPackage(string $package, string $version, Comment $comment, int $wholeMatchStartOffset)
145146
{
@@ -168,7 +169,7 @@ private function satisfiesPhpPlatformPackage(string $package, string $version, C
168169
}
169170

170171
/**
171-
* @return bool|RuleError
172+
* @return bool|IdentifierRuleError
172173
*/
173174
private function satisfiesVirtualPackage(string $package, string $version, Comment $comment, int $wholeMatchStartOffset)
174175
{
@@ -205,7 +206,7 @@ private function satisfiesVirtualPackage(string $package, string $version, Comme
205206
}
206207

207208
/**
208-
* @return RuleError|string
209+
* @return IdentifierRuleError|string
209210
*/
210211
private function readPhpPlatformVersion(Comment $comment, int $wholeMatchStartOffset)
211212
{
@@ -253,7 +254,7 @@ private function readPhpPlatformVersion(Comment $comment, int $wholeMatchStartOf
253254
}
254255

255256
/**
256-
* @return bool|RuleError
257+
* @return bool|IdentifierRuleError
257258
*/
258259
private function satisfiesInstalledPackage(string $package, string $version, Comment $comment, int $wholeMatchStartOffset)
259260
{

src/TodoBySymfonyDeprecationRule.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Composer\Semver\VersionParser;
77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
9+
use PHPStan\Rules\IdentifierRuleError;
910
use PHPStan\Rules\Rule;
1011
use PHPStan\Rules\RuleError;
1112
use PHPStan\Rules\RuleErrorBuilder;
@@ -90,7 +91,7 @@ public function processNode(Node $node, Scope $scope): array
9091
}
9192

9293
/**
93-
* @return bool|RuleError
94+
* @return bool|IdentifierRuleError
9495
*/
9596
private function satisfiesInstalledPackage(string $package, string $version)
9697
{
@@ -104,9 +105,9 @@ private function satisfiesInstalledPackage(string $package, string $version)
104105
try {
105106
return InstalledVersions::satisfies($versionParser, $package, '>='.$version);
106107
} catch (UnexpectedValueException $e) {
107-
return RuleErrorBuilder::message(
108-
'Invalid version constraint "' . $version . '" for package "' . $package . '".',
109-
)->build();
108+
return RuleErrorBuilder::message('Invalid version constraint "' . $version . '" for package "' . $package . '".')
109+
->identifier(ExpiredCommentErrorBuilder::ERROR_IDENTIFIER_PREFIX.self::ERROR_IDENTIFIER)
110+
->build();
110111
}
111112
}
112113
}

src/TodoByVersionRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function processNode(Node $node, Scope $scope): array
7979
return [
8080
RuleErrorBuilder::message($e->getMessage())
8181
->tip('See https://github.com/staabm/phpstan-todo-by#could-not-determine-latest-git-tag-error')
82+
->identifier(ExpiredCommentErrorBuilder::ERROR_IDENTIFIER_PREFIX.self::ERROR_IDENTIFIER)
8283
->build(),
8384
];
8485
}

src/utils/CommentMatcher.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public static function matchComments(Node $node, string $pattern): iterable
2020
$node instanceof Node\Stmt\InlineHTML
2121
|| $node instanceof Node\Name
2222
|| $node instanceof Node\Identifier
23-
|| $node instanceof \PHPStan\Node\CollectedDataNode // see https://github.com/phpstan/phpstan/discussions/11701
2423
) {
2524
// prevent unnecessary work / reduce memory consumption
2625
return [];

src/utils/ExpiredCommentErrorBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function buildError(
2323
string $errorIdentifier,
2424
?string $tip,
2525
int $wholeMatchStartOffset
26-
): \PHPStan\Rules\RuleError {
26+
): \PHPStan\Rules\IdentifierRuleError {
2727
return $this->build(
2828
$comment,
2929
$startLine,
@@ -45,7 +45,7 @@ public function buildFileError(
4545
int $wholeMatchStartOffset,
4646
string $file,
4747
int $line
48-
): \PHPStan\Rules\RuleError {
48+
): \PHPStan\Rules\IdentifierRuleError {
4949
return $this->build(
5050
$comment,
5151
$startLine,
@@ -67,7 +67,7 @@ private function build(
6767
int $wholeMatchStartOffset,
6868
?string $file,
6969
?int $line
70-
): \PHPStan\Rules\RuleError {
70+
): \PHPStan\Rules\IdentifierRuleError {
7171
// Count the number of newlines between the start of the whole comment, and the start of the match.
7272
$newLines = substr_count($comment, "\n", 0, $wholeMatchStartOffset);
7373

src/utils/GitTagFetcher.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
final class GitTagFetcher implements TagFetcher
88
{
99
// fetch version of the latest created git tag
10-
public function fetchLatestTagVersion(?string $workingDirectory): ?string
10+
public function fetchLatestTagVersion(?string $workingDirectory): string
1111
{
1212
// requires tags have been fetched into the local clone
1313
// see https://github.com/staabm/phpstan-todo-by#reference-version
@@ -26,7 +26,6 @@ public function fetchLatestTagVersion(?string $workingDirectory): ?string
2626
throw new LatestTagNotFoundException('Could not determine latest git tag');
2727
}
2828

29-
// a repo might not contain any tags
30-
return $output[0] ?? null;
29+
return $output[0];
3130
}
3231
}

tests/IntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private function runAnalyse(string $file): array
3636
{
3737
$file = $this->getFileHelper()->normalizePath($file);
3838
/** @var Analyser $analyser */
39-
$analyser = self::getContainer()->getByType(Analyser::class);
39+
$analyser = self::getContainer()->getByType(Analyser::class); /** @phpstan-ignore phpstanApi.classConstant */
4040
/** @var FileHelper $fileHelper */
4141
$fileHelper = self::getContainer()->getByType(FileHelper::class);
4242
/** @phpstan-ignore-next-line missing bc promise */

0 commit comments

Comments
 (0)