Skip to content

Commit 141dc13

Browse files
Robert van Steenclaude
andcommitted
Fix CI: green PHPStan and the prefer-lowest / prefer-stable test matrix
Pre-existing failures unrelated to the Psl arg fix, surfaced now that the suite runs to completion: - StrictComparisonOfObjectsRule::processNode() must return list<IdentifierRuleError>; add ->identifier() so the builder yields one. - basepath(): realpath() is string|false. Guard both calls so preg_match receives a string and the function never returns false. - RestrictImplicitDependencyUsage test used Psl\Collection\Vector as the "undefined package" example, but php-standard-library is now a declared dependency (the rule itself uses Psl\Type), so Psl\ is an allowed namespace. Use SebastianBergmann\Diff\Differ — installed transitively via phpunit but not declared — which is genuinely an implicit dependency. - Raise phpstan/phpstan floor to ^2.1.13: the rule implements RestrictedClassNameUsageExtension, added in 2.1.13, so prefer-lowest previously resolved 2.1.0 (missing the interface) and fatal-errored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f59a543 commit 141dc13

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"require": {
2222
"php": "^8.3",
23-
"phpstan/phpstan": "^2.1",
23+
"phpstan/phpstan": "^2.1.13",
2424
"php-standard-library/php-standard-library": "^4.0 || ^5.0 || ^6.0"
2525
},
2626
"require-dev": {

‎src/Rules/StrictComparisonOfObjectsRule.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function processNode(Node $node, Scope $scope): array
5454
$rightTypeDescription,
5555
$expectedType->describe(VerbosityLevel::typeOnly())
5656
))
57+
->identifier('superscript.strictComparisonOfObjects')
5758
->build(),
5859
];
5960
}

‎src/basepath.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ function basepath(): ?string
77
{
88
$real_path = realpath(__DIR__);
99

10+
if ($real_path === false) {
11+
return null;
12+
}
13+
1014
preg_match(
1115
"/.+\b(vendor\/.+)/",
1216
$real_path,
@@ -30,7 +34,7 @@ function basepath(): ?string
3034

3135
$project_path = realpath(__DIR__ . DIRECTORY_SEPARATOR . $out);
3236

33-
if ( !file_exists($project_path . DIRECTORY_SEPARATOR . "composer.json") ) {
37+
if ( $project_path === false || !file_exists($project_path . DIRECTORY_SEPARATOR . "composer.json") ) {
3438
return null;
3539
}
3640

‎tests/Rules/RestrictImplicitDepndencyUsage/RestrictImplicitDependencyUsageTest.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use PHPUnit\Framework\Attributes\DataProvider;
1717
use PHPUnit\Framework\Attributes\Test;
1818
use PHPUnit\Framework\TestCase;
19-
use Psl\Collection\Vector;
2019
use Superscript\PHPStanRules\Rules\RestrictImplicitDependencyUsage;
2120

2221
final class RestrictImplicitDependencyUsageTest extends PHPStanTestCase
@@ -65,6 +64,9 @@ public function it_can_be_restricted(string $class): void
6564

6665
public static function restrictedCases(): \Generator
6766
{
68-
yield 'class from undefined package' => [\Psl\Collection\Vector::class];
67+
// sebastian/diff is installed transitively (via phpunit) but not
68+
// declared in this package's composer.json, so a class from its
69+
// namespace must be flagged as an implicit-dependency usage.
70+
yield 'class from undefined package' => [\SebastianBergmann\Diff\Differ::class];
6971
}
7072
}

0 commit comments

Comments
 (0)