Skip to content

Commit

Permalink
Prepare for PHPStan 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk committed Oct 7, 2024
1 parent 5bc64db commit fda3957
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"require": {
"php": "~8.2.0 || ~8.3.0",
"phpstan/phpstan": "^1.12.4"
"phpstan/phpstan": "^2"
},
"require-dev": {
"laminas/laminas-cache": "^3.12.2",
Expand All @@ -33,11 +33,13 @@
"laminas/laminas-mvc": "^3.7.0",
"laminas/laminas-paginator": "^2.18.1",
"laminas/laminas-validator": "^2.64.1",
"phpstan/phpstan-deprecation-rules": "^1.2.1",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-deprecation-rules": "^2",
"phpstan/phpstan-phpunit": "^2",
"phpunit/phpunit": "^9.6.21",
"slam/php-cs-fixer-extensions": "^3.11.1"
"slam/php-cs-fixer-extensions": "^3.12.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
"conflict": {
"laminas/laminas-cache": "<3.12",
"laminas/laminas-filter": "<2.37",
Expand Down
5 changes: 3 additions & 2 deletions src/Rules/Laminas/ServiceManagerGetMethodCallRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use Psr\Container\ContainerInterface as PsrContainerInterface;
Expand Down Expand Up @@ -92,14 +93,14 @@ public function processNode(Node $node, Scope $scope): array
}
}

return [\sprintf(
return [RuleErrorBuilder::message(\sprintf(
'The service "%s" was not configured in %s%s.',
$serviceName,
$calledOnType instanceof ObjectServiceManagerType
? $calledOnType->getServiceName()
: $calledOnType->getClassName(),
$classDoesNotExistNote
)];
))->identifier('servicemanager.servicenotconfigured')->build()];
}

/** @phpstan-assert-if-true ObjectType $type */
Expand Down
2 changes: 1 addition & 1 deletion tests/LaminasIntegration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
final class IntegrationTest extends LevelsTestCase
{
public function dataTopics(): array
public static function dataTopics(): array
{
return [
['serviceManagerDynamicReturn'],
Expand Down
7 changes: 7 additions & 0 deletions tests/LaminasIntegration/data/controllerPluginMethod-10.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"message": "Cannot call method isFoo() on mixed.",
"line": 16,
"ignorable": true
}
]
12 changes: 12 additions & 0 deletions tests/LaminasIntegration/data/serviceManagerDynamicReturn-4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"message": "Expression \"(static function (\\LaminasPhpStan\\TestAsset\\FooService $fooService): void {…\" on a separate line does not do anything.",
"line": 52,
"ignorable": true
},
{
"message": "Expression \"(static function (\\LaminasPhpStan\\TestAsset\\FooInterface $fooService): void {…\" on a separate line does not do anything.",
"line": 55,
"ignorable": true
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"ignorable": true
},
{
"message": "Property class@anonymous/stdlibAbstractOptionsProperties.php:27::$myxyz is not writable.",
"message": "Property Laminas\\Stdlib\\AbstractOptions@anonymous/stdlibAbstractOptionsProperties.php:27::$myxyz is not writable.",
"line": 37,
"ignorable": true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "Property class@anonymous/stdlibAbstractOptionsProperties.php:27::$myxyz is never read, only written.",
"message": "Property Laminas\\Stdlib\\AbstractOptions@anonymous/stdlibAbstractOptionsProperties.php:27::$myxyz is never read, only written.",
"line": 28,
"ignorable": true
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Type/Laminas/PluginMethodReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
use PHPStan\Reflection\FunctionVariant;
use PHPStan\TrinaryLogic;
use PHPStan\Type\ObjectType;
use PHPUnit\Framework\TestCase;
use PHPStan\Testing\PHPStanTestCase;
use stdClass;

/**
* @covers \LaminasPhpStan\Type\Laminas\PluginMethodReflection
*/
final class PluginMethodReflectionTest extends TestCase
final class PluginMethodReflectionTest extends PHPStanTestCase
{
public function testTrivialUsage(): void
{
$declaringClass = $this->createMock(ClassReflection::class);
$declaringClass = $this->createReflectionProvider()->getClass(stdClass::class);
$methodName = 'redirect';
$returnType = new ObjectType(stdClass::class);

Expand Down

0 comments on commit fda3957

Please sign in to comment.