Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Early return Collectors when narrow-param is disabled #44

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +22,8 @@
public function __construct(
private ApiDocStmtAnalyzer $apiDocStmtAnalyzer,
private PublicClassMethodMatcher $publicClassMethodMatcher,
private CollectorMetadataPrinter $collectorMetadataPrinter
private CollectorMetadataPrinter $collectorMetadataPrinter,
private Configuration $configuration
) {
}

Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Collector/MethodCall/MethodCallArgTypesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@
public function __construct(
private ClassMethodCallReferenceResolver $classMethodCallReferenceResolver,
private CollectorMetadataPrinter $collectorMetadataPrinter,
private Configuration $configuration
) {
}

Expand All @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/Collector/MethodCallableNode/MethodCallableCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,6 +23,7 @@
{
public function __construct(
private ClassMethodCallReferenceResolver $classMethodCallReferenceResolver,
private Configuration $configuration
) {
}

Expand All @@ -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;
Expand Down
Loading