From f88ab09680cbe22e9ca23e13405c50d111452c50 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 11 Nov 2024 10:31:40 +0100 Subject: [PATCH] Remove unnecessary `ParametersAcceptorSelector::selectSingle` handling (#9) * Remove unnecessary `ParametersAcceptorSelector::selectSingle` handling * Update composer.json * update class-leak * class-leak skip TypeExtenion classes * Update composer.json * Update composer.json --------- Co-authored-by: Markus Staab --- .github/workflows/code_analysis.yaml | 2 +- composer.json | 4 ++-- .../MethodCall/ContainerGetReturnTypeExtension.php | 2 +- .../MethodCall/LaravelContainerMakeTypeExtension.php | 2 +- src/TypeResolver/ClassConstFetchReturnTypeResolver.php | 6 ++---- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index d82bc414..29b9ccff 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -38,7 +38,7 @@ jobs: - name: 'Check Active Classes' - run: vendor/bin/class-leak check src --ansi + run: vendor/bin/class-leak check src --ansi --skip-suffix "TypeExtension" name: ${{ matrix.actions.name }} runs-on: ubuntu-latest diff --git a/composer.json b/composer.json index e5e6e974..64937a7b 100644 --- a/composer.json +++ b/composer.json @@ -11,12 +11,12 @@ "illuminate/container": "^10.39", "phpstan/extension-installer": "^1.3", "phpunit/phpunit": "^10.3", - "rector/rector": "^0.18", + "rector/rector": "^1.2", "symfony/dependency-injection": "^6.4", "symfony/finder": "^6.2", "symplify/easy-coding-standard": "^12.0", "symplify/phpstan-rules": "^12.4", - "tomasvotruba/class-leak": "^0.2", + "tomasvotruba/class-leak": "^1.1.2", "tracy/tracy": "^2.9" }, "autoload": { diff --git a/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php b/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php index 91be7d41..2863beb9 100644 --- a/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php +++ b/src/TypeExtension/MethodCall/ContainerGetReturnTypeExtension.php @@ -38,7 +38,7 @@ public function getTypeFromMethodCall( MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope - ): Type { + ): ?Type { return $this->classConstFetchReturnTypeResolver->resolve($methodReflection, $methodCall); } } diff --git a/src/TypeExtension/MethodCall/LaravelContainerMakeTypeExtension.php b/src/TypeExtension/MethodCall/LaravelContainerMakeTypeExtension.php index 378749ae..be8fb5de 100644 --- a/src/TypeExtension/MethodCall/LaravelContainerMakeTypeExtension.php +++ b/src/TypeExtension/MethodCall/LaravelContainerMakeTypeExtension.php @@ -36,7 +36,7 @@ public function getTypeFromMethodCall( MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope - ): Type { + ): ?Type { return $this->classConstFetchReturnTypeResolver->resolve($methodReflection, $methodCall); } } diff --git a/src/TypeResolver/ClassConstFetchReturnTypeResolver.php b/src/TypeResolver/ClassConstFetchReturnTypeResolver.php index a2f9ab2c..6a280af4 100644 --- a/src/TypeResolver/ClassConstFetchReturnTypeResolver.php +++ b/src/TypeResolver/ClassConstFetchReturnTypeResolver.php @@ -18,10 +18,8 @@ final class ClassConstFetchReturnTypeResolver { - public function resolve(MethodReflection $methodReflection, MethodCall $methodCall): Type + public function resolve(MethodReflection $methodReflection, MethodCall $methodCall): ?Type { - $returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); - if (! isset($methodCall->args[0])) { throw new ShouldNotHappenException('Not supported without argument'); } @@ -45,6 +43,6 @@ public function resolve(MethodReflection $methodReflection, MethodCall $methodCa return new ObjectType($className); } - return $returnType; + return null; } }