diff --git a/src/Rule/CurrencyAvailableWithinToCurrenciesContainsRector.php b/src/Rule/CurrencyAvailableWithinToCurrenciesContainsRector.php index b25a886..c88c759 100644 --- a/src/Rule/CurrencyAvailableWithinToCurrenciesContainsRector.php +++ b/src/Rule/CurrencyAvailableWithinToCurrenciesContainsRector.php @@ -7,7 +7,7 @@ use Money\Currency; use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; -use PHPStan\Type\ObjectType; +use PHPStan\Type\TypeWithClassName; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -49,10 +49,10 @@ public function refactor(Node $node): ?Node private function shouldSkip(MethodCall $node): bool { - /** @var ObjectType $executedOn */ $executedOn = $this->nodeTypeResolver->getNativeType($node->var); - return $executedOn->getClassName() !== Currency::class + return !$executedOn instanceof TypeWithClassName + || $executedOn->getClassName() !== Currency::class || $this->nodeNameResolver->getName($node->name) !== 'isAvailableWithin'; } } diff --git a/src/Rule/MultiplyAndDivideByStringRector.php b/src/Rule/MultiplyAndDivideByStringRector.php index a01149e..7e49a3a 100644 --- a/src/Rule/MultiplyAndDivideByStringRector.php +++ b/src/Rule/MultiplyAndDivideByStringRector.php @@ -17,7 +17,7 @@ use PhpParser\Node\Scalar\String_; use PHPStan\Analyser\MutatingScope; use PHPStan\Type\FloatType; -use PHPStan\Type\ObjectType; +use PHPStan\Type\TypeWithClassName; use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface; use Rector\Core\PhpParser\AstResolver; use Rector\Core\Rector\AbstractRector; @@ -123,10 +123,10 @@ public function configure(array $configuration): void private function shouldSkip(MethodCall $node): bool { - /** @var ObjectType $executedOn */ $executedOn = $this->nodeTypeResolver->getNativeType($node->var); - return $executedOn->getClassName() !== Money::class + return !$executedOn instanceof TypeWithClassName + || $executedOn->getClassName() !== Money::class || !$node->name instanceof Identifier || !in_array($node->name->toLowerString(), ['divide', 'multiply'], true); } diff --git a/tests/Rule/CurrencyAvailableWithinToCurrenciesContainsRector/Fixture/skip_union_types.php.inc b/tests/Rule/CurrencyAvailableWithinToCurrenciesContainsRector/Fixture/skip_union_types.php.inc new file mode 100644 index 0000000..6d0fd14 --- /dev/null +++ b/tests/Rule/CurrencyAvailableWithinToCurrenciesContainsRector/Fixture/skip_union_types.php.inc @@ -0,0 +1,28 @@ + 'other', 'data']; + } + return false; +} + +$collection = new CurrencyList([new Currency('PLN')]); +willReturnCurrencyOrSomethingDifferent() + ->isAvailableWithin($collection); + +?> + diff --git a/tests/Rule/MultiplyAndDivideByStringRector/Fixture/skip_union_types.php.inc b/tests/Rule/MultiplyAndDivideByStringRector/Fixture/skip_union_types.php.inc new file mode 100644 index 0000000..2856b08 --- /dev/null +++ b/tests/Rule/MultiplyAndDivideByStringRector/Fixture/skip_union_types.php.inc @@ -0,0 +1,44 @@ + 'other', 'data']; + } + return false; + } + + /** + * @return Money|array|false + */ + public function bar() + { + return self::foo(); + } +} + +$unionReturning = new UnionReturning(); +$unionReturning->bar()->divide(1); +$unionReturning->bar()->multiply(2); +$unionReturning->bar()->divide(1.1); +$unionReturning->bar()->multiply(2.5); + +UnionReturning::foo()->divide(3); +UnionReturning::foo()->multiply(4); +UnionReturning::foo()->divide(3.5); +UnionReturning::foo()->multiply(4.6);