diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 21ef3418..b0b06293 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -26,7 +26,7 @@ jobs: - name: 'Coding Standard' - run: composer fix-cs --ansi + run: composer check-cs --ansi - name: 'Tests' diff --git a/src/Collector/MethodCall/MethodCallArgTypesCollector.php b/src/Collector/MethodCall/MethodCallArgTypesCollector.php index b410bc70..ac8a5f6c 100644 --- a/src/Collector/MethodCall/MethodCallArgTypesCollector.php +++ b/src/Collector/MethodCall/MethodCallArgTypesCollector.php @@ -4,12 +4,12 @@ namespace Rector\TypePerfect\Collector\MethodCall; -use PhpParser\Node\Identifier; -use PHPStan\Reflection\ExtendedMethodReflection; use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Identifier; use PHPStan\Analyser\Scope; use PHPStan\Collectors\Collector; +use PHPStan\Reflection\ExtendedMethodReflection; use Rector\TypePerfect\Matcher\ClassMethodCallReferenceResolver; use Rector\TypePerfect\Printer\CollectorMetadataPrinter; use Rector\TypePerfect\ValueObject\MethodCallReference; @@ -36,13 +36,13 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): ?array { - if ($node->isFirstClassCallable() || $node->getArgs() === [] || !$node->name instanceof Identifier) { + if ($node->isFirstClassCallable() || $node->getArgs() === [] || ! $node->name instanceof Identifier) { return null; } $methodCalledOnType = $scope->getType($node->var); $methodReflection = $scope->getMethodReflection($methodCalledOnType, $node->name->name); - if (!$methodReflection instanceof ExtendedMethodReflection) { + if (! $methodReflection instanceof ExtendedMethodReflection) { return null; } diff --git a/src/Rules/NarrowReturnObjectTypeRule.php b/src/Rules/NarrowReturnObjectTypeRule.php index 30563304..e2ccef62 100644 --- a/src/Rules/NarrowReturnObjectTypeRule.php +++ b/src/Rules/NarrowReturnObjectTypeRule.php @@ -14,11 +14,12 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; +use Rector\TypePerfect\Configuration; use Rector\TypePerfect\NodeFinder\ReturnNodeFinder; use Rector\TypePerfect\Reflection\MethodNodeAnalyser; /** - * @see \Rector\TypePerfect\Tests\Rules\RequireSpecificReturnTypeOverAbstractRule\RequireSpecificReturnTypeOverAbstractRuleTest + * @see \Rector\TypePerfect\Tests\Rules\NarrowReturnObjectTypeRule\NarrowReturnObjectTypeRuleTest * * @implements Rule */ @@ -32,6 +33,7 @@ public function __construct( private ReturnNodeFinder $returnNodeFinder, private MethodNodeAnalyser $methodNodeAnalyser, + private Configuration $configuration ) { } @@ -49,6 +51,10 @@ public function getNodeType(): string */ public function processNode(Node $node, Scope $scope): array { + if (! $this->configuration->isNarrowEnabled()) { + return []; + } + if (! $node->returnType instanceof FullyQualified) { return []; } diff --git a/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php b/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php index 8063819d..cd50ab05 100644 --- a/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php +++ b/tests/Rules/NarrowPublicClassMethodParamTypeRule/NarrowPublicClassMethodParamTypeRuleTest.php @@ -147,7 +147,7 @@ public static function provideData(): Iterator $argErrorMessage = sprintf(NarrowPublicClassMethodParamTypeRule::ERROR_MESSAGE, 'int'); yield [[ - __DIR__ . '/Fixture/HandleDefaultValue.php' + __DIR__ . '/Fixture/HandleDefaultValue.php', ], [[$argErrorMessage, 15]]]; }