From 58af904a07785b5b0184c8a5482dc0ed6c55446a Mon Sep 17 00:00:00 2001 From: Sascha Egerer Date: Wed, 12 Apr 2023 23:13:18 +0200 Subject: [PATCH] [BUGFIX] Fix fatal error in QueryInterfaceDynamicReturnTypeExtension In some rare cases (only in combination with rector?) the QueryInterfaceDynamicReturnTypeExtension failed with an exception as it has been tried to convert a Repository name to a model name even if the QueryInterface was not used in a Repository. It is checked if we're in the scope of a repository and if not we use a mixed type as we could not find out which type exactly it is. --- .../QueryInterfaceDynamicReturnTypeExtension.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Type/QueryInterfaceDynamicReturnTypeExtension.php b/src/Type/QueryInterfaceDynamicReturnTypeExtension.php index 2bf8c79..e18ab79 100644 --- a/src/Type/QueryInterfaceDynamicReturnTypeExtension.php +++ b/src/Type/QueryInterfaceDynamicReturnTypeExtension.php @@ -11,11 +11,13 @@ use PHPStan\Type\ErrorType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IntegerType; +use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use SaschaEgerer\PhpstanTypo3\Helpers\Typo3ClassNamingUtilityTrait; use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult; use TYPO3\CMS\Extbase\Persistence\QueryInterface; +use TYPO3\CMS\Extbase\Persistence\Repository; class QueryInterfaceDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { @@ -51,12 +53,15 @@ public function getTypeFromMethodCall( if ($classReflection === null) { return new ErrorType(); } + $modelType = [new MixedType()]; - $modelName = $this->translateRepositoryNameToModelName( - $classReflection->getName() - ); + if ($classReflection->isSubclassOf(Repository::class)) { + $modelName = $this->translateRepositoryNameToModelName( + $classReflection->getName() + ); - $modelType = [new ObjectType($modelName)]; + $modelType = [new ObjectType($modelName)]; + } } if ($argument !== null) {