diff --git a/src/Collector/ClassMethod/PublicClassMethodParamTypesCollector.php b/src/Collector/ClassMethod/PublicClassMethodParamTypesCollector.php index 39f47742..89edda68 100644 --- a/src/Collector/ClassMethod/PublicClassMethodParamTypesCollector.php +++ b/src/Collector/ClassMethod/PublicClassMethodParamTypesCollector.php @@ -9,6 +9,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Collectors\Collector; use PHPStan\Reflection\ClassReflection; +use Rector\TypePerfect\Configuration; use Rector\TypePerfect\Matcher\Collector\PublicClassMethodMatcher; use Rector\TypePerfect\PhpDoc\ApiDocStmtAnalyzer; use Rector\TypePerfect\Printer\CollectorMetadataPrinter; @@ -21,7 +22,8 @@ public function __construct( private ApiDocStmtAnalyzer $apiDocStmtAnalyzer, private PublicClassMethodMatcher $publicClassMethodMatcher, - private CollectorMetadataPrinter $collectorMetadataPrinter + private CollectorMetadataPrinter $collectorMetadataPrinter, + private Configuration $configuration ) { } @@ -36,6 +38,10 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): ?array { + if (! $this->configuration->isNarrowParamEnabled()) { + return null; + } + if ($node->params === []) { return null; } diff --git a/src/Collector/MethodCall/MethodCallArgTypesCollector.php b/src/Collector/MethodCall/MethodCallArgTypesCollector.php index ac8a5f6c..ffd412de 100644 --- a/src/Collector/MethodCall/MethodCallArgTypesCollector.php +++ b/src/Collector/MethodCall/MethodCallArgTypesCollector.php @@ -10,6 +10,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Collectors\Collector; use PHPStan\Reflection\ExtendedMethodReflection; +use Rector\TypePerfect\Configuration; use Rector\TypePerfect\Matcher\ClassMethodCallReferenceResolver; use Rector\TypePerfect\Printer\CollectorMetadataPrinter; use Rector\TypePerfect\ValueObject\MethodCallReference; @@ -22,6 +23,7 @@ public function __construct( private ClassMethodCallReferenceResolver $classMethodCallReferenceResolver, private CollectorMetadataPrinter $collectorMetadataPrinter, + private Configuration $configuration ) { } @@ -36,6 +38,10 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): ?array { + if (! $this->configuration->isNarrowParamEnabled()) { + return null; + } + if ($node->isFirstClassCallable() || $node->getArgs() === [] || ! $node->name instanceof Identifier) { return null; } diff --git a/src/Collector/MethodCallableNode/MethodCallableCollector.php b/src/Collector/MethodCallableNode/MethodCallableCollector.php index 6d00cdd6..0d52c657 100644 --- a/src/Collector/MethodCallableNode/MethodCallableCollector.php +++ b/src/Collector/MethodCallableNode/MethodCallableCollector.php @@ -8,6 +8,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Collectors\Collector; use PHPStan\Node\MethodCallableNode; +use Rector\TypePerfect\Configuration; use Rector\TypePerfect\Matcher\ClassMethodCallReferenceResolver; use Rector\TypePerfect\ValueObject\MethodCallReference; @@ -22,6 +23,7 @@ { public function __construct( private ClassMethodCallReferenceResolver $classMethodCallReferenceResolver, + private Configuration $configuration ) { } @@ -36,6 +38,10 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): ?array { + if (! $this->configuration->isNarrowParamEnabled()) { + return null; + } + $classMethodCallReference = $this->classMethodCallReferenceResolver->resolve($node, $scope, true); if (! $classMethodCallReference instanceof MethodCallReference) { return null;