From 81fe964bc73548bf9462b7034ac5724ecea6bdb5 Mon Sep 17 00:00:00 2001 From: eden Date: Mon, 6 Nov 2023 16:39:28 +0100 Subject: [PATCH] refact(*): rector --- src/ReturnTypes/RequestDateExtension.php | 3 +-- src/Rules/CarbonCopyRule.php | 4 +--- tests/ExecutesLarastan.php | 2 +- tests/FeatureTest.php | 2 +- tests/RulesTest.php | 4 +--- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/ReturnTypes/RequestDateExtension.php b/src/ReturnTypes/RequestDateExtension.php index c53f28a..d0ad09f 100644 --- a/src/ReturnTypes/RequestDateExtension.php +++ b/src/ReturnTypes/RequestDateExtension.php @@ -10,7 +10,6 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; -use function get_class; class RequestDateExtension implements DynamicMethodReturnTypeExtension { @@ -29,6 +28,6 @@ public function getTypeFromMethodCall( MethodCall $methodCall, Scope $scope, ): Type { - return TypeCombinator::addNull(new ObjectType(get_class(now()))); + return TypeCombinator::addNull(new ObjectType(now()::class)); } } diff --git a/src/Rules/CarbonCopyRule.php b/src/Rules/CarbonCopyRule.php index 6b90d35..90fd211 100644 --- a/src/Rules/CarbonCopyRule.php +++ b/src/Rules/CarbonCopyRule.php @@ -47,9 +47,7 @@ public function processNode(Node $node, Scope $scope): array $scope, $node->var, '', - static function (Type $type) use ($name): bool { - return $type->canCallMethods()->yes() && $type->hasMethod($name)->yes(); - } + static fn (Type $type): bool => $type->canCallMethods()->yes() && $type->hasMethod($name)->yes() ); $type = $typeResult->getType(); diff --git a/tests/ExecutesLarastan.php b/tests/ExecutesLarastan.php index 47dd788..c122569 100644 --- a/tests/ExecutesLarastan.php +++ b/tests/ExecutesLarastan.php @@ -24,7 +24,7 @@ public function execLarastan(string $filename) $jsonResult ); - return json_decode($jsonResult[0], true); + return json_decode($jsonResult[0], true, 512, JSON_THROW_ON_ERROR); } private function analyze(string $file): int diff --git a/tests/FeatureTest.php b/tests/FeatureTest.php index fe6e44e..3246b82 100644 --- a/tests/FeatureTest.php +++ b/tests/FeatureTest.php @@ -21,7 +21,7 @@ protected function setUp(): void $this->configPath = __DIR__ . '/Features/phpstan-tests.neon'; } - public function getFeatures(): array + public static function getFeatures(): array { $calls = []; $baseDir = __DIR__ . DIRECTORY_SEPARATOR . 'Features' . DIRECTORY_SEPARATOR; diff --git a/tests/RulesTest.php b/tests/RulesTest.php index dc63b9e..5d6b07d 100644 --- a/tests/RulesTest.php +++ b/tests/RulesTest.php @@ -37,8 +37,6 @@ protected function findErrorsByLine(string $filename): array { $errors = $this->findErrors(realpath($filename)); - return collect($errors['messages'] ?? [])->mapWithKeys(function ($message) { - return [$message['line'] => $message['message']]; - })->toArray(); + return collect($errors['messages'] ?? [])->mapWithKeys(fn ($message) => [$message['line'] => $message['message']])->toArray(); } }