From e3e77739a205a8825d56fb9495620923b20ca9fc Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 11 Nov 2024 14:28:47 +0100 Subject: [PATCH] Update to PHPStan 2.0 --- composer.json | 6 +++--- src/Type/AssertTypeSpecifyingExtension.php | 3 ++- src/Type/MatchesTypeSpecifyingExtension.php | 3 ++- src/Type/TypeShapeReturnTypeExtension.php | 3 +-- tests/Type/data/coerce.php | 2 +- tests/Type/data/matches.php | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 50f42c0..d3ab5df 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "phpstan/phpstan": "^1.12" + "phpstan/phpstan": "^2.0" }, "conflict": { "azjezz/psl": "<1.6||>=4.0" @@ -17,8 +17,8 @@ "composer/semver": "^3.3", "nikic/php-parser": "^4.14.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^1.4.0", - "phpstan/phpstan-strict-rules": "^1.6.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^9.6" }, "config": { diff --git a/src/Type/AssertTypeSpecifyingExtension.php b/src/Type/AssertTypeSpecifyingExtension.php index 6a6f7a2..8a6f81d 100644 --- a/src/Type/AssertTypeSpecifyingExtension.php +++ b/src/Type/AssertTypeSpecifyingExtension.php @@ -42,7 +42,8 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod return $this->typeSpecifier->create( $args[0]->value, $scope->getType($node), - TypeSpecifierContext::createTruthy() + TypeSpecifierContext::createTruthy(), + $scope ); } diff --git a/src/Type/MatchesTypeSpecifyingExtension.php b/src/Type/MatchesTypeSpecifyingExtension.php index 9c8db42..eb36ca8 100644 --- a/src/Type/MatchesTypeSpecifyingExtension.php +++ b/src/Type/MatchesTypeSpecifyingExtension.php @@ -44,7 +44,8 @@ public function specifyTypes(MethodReflection $methodReflection, MethodCall $nod return $this->typeSpecifier->create( $args[0]->value, $specType->getTemplateType(TypeInterface::class, 'T'), - $context + $context, + $scope ); } diff --git a/src/Type/TypeShapeReturnTypeExtension.php b/src/Type/TypeShapeReturnTypeExtension.php index fdfa305..4163a21 100644 --- a/src/Type/TypeShapeReturnTypeExtension.php +++ b/src/Type/TypeShapeReturnTypeExtension.php @@ -12,7 +12,6 @@ use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; -use PHPStan\Type\TypeUtils; use Psl\Type\Internal\OptionalType; use Psl\Type\TypeInterface; use function count; @@ -33,7 +32,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } $arg = $scope->getType($args[0]->value); - $arrays = TypeUtils::getConstantArrays($arg); + $arrays = $arg->getConstantArrays(); if (count($arrays) === 0) { return null; } diff --git a/tests/Type/data/coerce.php b/tests/Type/data/coerce.php index 45b17ab..2d49000 100644 --- a/tests/Type/data/coerce.php +++ b/tests/Type/data/coerce.php @@ -26,7 +26,7 @@ public function coerceShape(array $input): void $output = $specification->coerce($input); assertType('array{name: string, age: int, location?: array{city: string, state: string, country: string}}', $output); - assertType('array', $input); + assertType('array', $input); } public function coerceInt($i): void diff --git a/tests/Type/data/matches.php b/tests/Type/data/matches.php index 1018904..7678eae 100644 --- a/tests/Type/data/matches.php +++ b/tests/Type/data/matches.php @@ -26,7 +26,7 @@ public function matchesShape(array $a): void if ($specification->matches($a)) { assertType('array{name: string, age: int, location?: array{city: string, state: string, country: string}}', $a); } else { - assertType('array', $a); + assertType('array', $a); } }