diff --git a/src/PHPStan/Type/Helper.php b/src/PHPStan/Type/Helper.php index 4479d0bd..b136c719 100644 --- a/src/PHPStan/Type/Helper.php +++ b/src/PHPStan/Type/Helper.php @@ -1,17 +1,18 @@ getType($methodCall->var); + $type = $scope->getType($methodCall->var); $translatableClass = $type->getReferencedClasses()[0]; return $broker @@ -23,7 +24,7 @@ public static function getTranslationClass(Broker $broker, MethodCall $methodCal public static function getTranslatableClass(Broker $broker, MethodCall $methodCall, Scope $scope): string { - $type = $scope->getType($methodCall->var); + $type = $scope->getType($methodCall->var); $translatableClass = $type->getReferencedClasses()[0]; return $broker diff --git a/src/PHPStan/Type/TranslatableGetTranslationsDynamicMethodReturnTypeExtension.php b/src/PHPStan/Type/TranslatableGetTranslationsDynamicMethodReturnTypeExtension.php index 24271c5f..efd7b20c 100644 --- a/src/PHPStan/Type/TranslatableGetTranslationsDynamicMethodReturnTypeExtension.php +++ b/src/PHPStan/Type/TranslatableGetTranslationsDynamicMethodReturnTypeExtension.php @@ -5,6 +5,7 @@ namespace Knp\DoctrineBehaviors\PHPStan\Type; use Doctrine\Common\Collections\Collection; +use function in_array; use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface; use PhpParser\Node\Expr\MethodCall; use PHPStan\Analyser\Scope; @@ -15,11 +16,14 @@ use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; final class TranslatableGetTranslationsDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension, BrokerAwareExtension { - /** @var Broker */ + /** + * @var Broker + */ private $broker; public function setBroker(Broker $broker): void @@ -34,11 +38,14 @@ public function getClass(): string public function isMethodSupported(MethodReflection $methodReflection): bool { - return \in_array($methodReflection->getName(), ['getTranslations', 'getNewTranslations'], true); + return in_array($methodReflection->getName(), ['getTranslations', 'getNewTranslations'], true); } - public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type - { + public function getTypeFromMethodCall( + MethodReflection $methodReflection, + MethodCall $methodCall, + Scope $scope + ): Type { $translationClass = Helper::getTranslationClass($this->broker, $methodCall, $scope); return TypeCombinator::intersect( diff --git a/src/PHPStan/Type/TranslatableTranslateDynamicMethodReturnTypeExtension.php b/src/PHPStan/Type/TranslatableTranslateDynamicMethodReturnTypeExtension.php index 5ff39f12..e906d44c 100644 --- a/src/PHPStan/Type/TranslatableTranslateDynamicMethodReturnTypeExtension.php +++ b/src/PHPStan/Type/TranslatableTranslateDynamicMethodReturnTypeExtension.php @@ -12,10 +12,13 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; final class TranslatableTranslateDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension, BrokerAwareExtension { - /** @var Broker */ + /** + * @var Broker + */ private $broker; public function setBroker(Broker $broker): void @@ -30,11 +33,14 @@ public function getClass(): string public function isMethodSupported(MethodReflection $methodReflection): bool { - return 'translate' === $methodReflection->getName(); + return $methodReflection->getName() === 'translate'; } - public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type - { + public function getTypeFromMethodCall( + MethodReflection $methodReflection, + MethodCall $methodCall, + Scope $scope + ): Type { $translationClass = Helper::getTranslationClass($this->broker, $methodCall, $scope); return new ObjectType($translationClass); diff --git a/src/PHPStan/Type/TranslationGetTranslatableDynamicMethodReturnTypeExtension.php b/src/PHPStan/Type/TranslationGetTranslatableDynamicMethodReturnTypeExtension.php index e7978e23..18f97ea1 100644 --- a/src/PHPStan/Type/TranslationGetTranslatableDynamicMethodReturnTypeExtension.php +++ b/src/PHPStan/Type/TranslationGetTranslatableDynamicMethodReturnTypeExtension.php @@ -12,10 +12,13 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; final class TranslationGetTranslatableDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension, BrokerAwareExtension { - /** @var Broker */ + /** + * @var Broker + */ private $broker; public function setBroker(Broker $broker): void @@ -30,11 +33,14 @@ public function getClass(): string public function isMethodSupported(MethodReflection $methodReflection): bool { - return 'getTranslatable' === $methodReflection->getName(); + return $methodReflection->getName() === 'getTranslatable'; } - public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): \PHPStan\Type\Type - { + public function getTypeFromMethodCall( + MethodReflection $methodReflection, + MethodCall $methodCall, + Scope $scope + ): Type { $translatableClass = Helper::getTranslatableClass($this->broker, $methodCall, $scope); return new ObjectType($translatableClass); diff --git a/tests/ORM/TranslatableInheritanceTest.php b/tests/ORM/TranslatableInheritanceTest.php index e0a9604c..bdb243be 100644 --- a/tests/ORM/TranslatableInheritanceTest.php +++ b/tests/ORM/TranslatableInheritanceTest.php @@ -5,7 +5,6 @@ namespace Knp\DoctrineBehaviors\Tests\ORM; use Doctrine\Persistence\ObjectRepository; -use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface; use Knp\DoctrineBehaviors\Tests\AbstractBehaviorTestCase; use Knp\DoctrineBehaviors\Tests\Fixtures\Entity\Translatable\ExtendedTranslatableEntity;