From c393f60e762d7ab9901756d671181a27fe4f65a7 Mon Sep 17 00:00:00 2001 From: Brad Miller <28307684+mad-briller@users.noreply.github.com> Date: Thu, 18 Jan 2024 19:51:06 +0000 Subject: [PATCH] Fully qualify all global function calls. (#718) * Fully qualify all global function calls. * Add the slevomat/coding-standards ReferenceUsedNames rule and fix violations. --- phpcs.xml | 1 + .../DeprecationHelperScope.php | 2 + src/DeprecatedScope/GroupLegacyScope.php | 1 + src/Drupal/DrupalAutoloader.php | 40 +++++++++++++++---- src/Drupal/DrupalServiceDefinition.php | 2 + src/Drupal/Extension.php | 23 +++++++---- src/Drupal/ExtensionDiscovery.php | 31 +++++++++----- src/Drupal/ExtensionMap.php | 4 ++ .../RecursiveExtensionFilterIterator.php | 12 ++++-- src/Drupal/ServiceMap.php | 2 + ...ieldMethodsViaMagicReflectionExtension.php | 1 + src/Reflection/EntityFieldReflection.php | 9 +++-- ...ntityFieldsViaMagicReflectionExtension.php | 4 +- .../FieldItemListPropertyReflection.php | 10 +++-- .../Classes/ClassExtendsInternalClassRule.php | 5 ++- .../Classes/PluginManagerInspectionRule.php | 1 + .../Deprecations/AccessDeprecatedConstant.php | 9 ++++- ...CreateInstanceContextConfigurationRule.php | 1 + .../ConfigEntityConfigExportRule.php | 1 + .../DeprecatedHookImplementation.php | 4 ++ ...PluginAnnotationContextDefinitionsRule.php | 1 + ...nyCmfRouteObjectInterfaceConstantsRule.php | 7 +++- ...nyCmfRoutingInClassMethodSignatureRule.php | 14 +++++-- .../Drupal/Coder/DiscouragedFunctionsRule.php | 3 ++ src/Rules/Drupal/LoadIncludeBase.php | 1 + src/Rules/Drupal/LoadIncludes.php | 8 +++- src/Rules/Drupal/ModuleLoadInclude.php | 11 +++-- .../PluginManagerSetsCacheBackendRule.php | 7 +++- src/Rules/Drupal/RenderCallbackRule.php | 8 ++++ .../Drupal/RequestStackGetMainRequestRule.php | 5 ++- ...estClassesProtectedPropertyModulesRule.php | 2 + .../Tests/BrowserTestBaseDefaultThemeRule.php | 8 +++- .../ContainerDynamicReturnTypeExtension.php | 2 + ...lassResolverDynamicReturnTypeExtension.php | 3 +- ...solverDynamicStaticReturnTypeExtension.php | 6 ++- src/Type/DrupalClassResolverReturnType.php | 1 + ...cEntityQueryDynamicReturnTypeExtension.php | 3 +- ...ccessControlHandlerReturnTypeExtension.php | 8 ++-- .../EntityQueryDynamicReturnTypeExtension.php | 1 + src/Type/EntityQuery/EntityQueryType.php | 1 + ...ntityStorageDynamicReturnTypeExtension.php | 10 +++-- .../GetQueryReturnTypeExtension.php | 4 +- ...erGetStorageDynamicReturnTypeExtension.php | 3 +- 43 files changed, 212 insertions(+), 68 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 67a48110..98d3782b 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -21,6 +21,7 @@ + diff --git a/src/DeprecatedScope/DeprecationHelperScope.php b/src/DeprecatedScope/DeprecationHelperScope.php index 5c078d35..e9f30b28 100644 --- a/src/DeprecatedScope/DeprecationHelperScope.php +++ b/src/DeprecatedScope/DeprecationHelperScope.php @@ -8,6 +8,8 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\MethodReflection; use PHPStan\Rules\Deprecations\DeprecatedScopeResolver; +use function class_exists; +use function count; final class DeprecationHelperScope implements DeprecatedScopeResolver { diff --git a/src/DeprecatedScope/GroupLegacyScope.php b/src/DeprecatedScope/GroupLegacyScope.php index 92b632f9..cb8068a4 100644 --- a/src/DeprecatedScope/GroupLegacyScope.php +++ b/src/DeprecatedScope/GroupLegacyScope.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Rules\Deprecations\DeprecatedScopeResolver; +use function strpos; final class GroupLegacyScope implements DeprecatedScopeResolver { diff --git a/src/Drupal/DrupalAutoloader.php b/src/Drupal/DrupalAutoloader.php index c6d2ded7..9b681dd5 100644 --- a/src/Drupal/DrupalAutoloader.php +++ b/src/Drupal/DrupalAutoloader.php @@ -3,10 +3,34 @@ namespace mglaman\PHPStanDrupal\Drupal; use Drupal\Core\DependencyInjection\ContainerNotInitializedException; +use Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter; use DrupalFinder\DrupalFinder; +use Drush\Drush; use PHPStan\DependencyInjection\Container; +use PHPUnit\Framework\Test; +use ReflectionClass; +use RuntimeException; use Symfony\Component\Finder\Finder; use Symfony\Component\Yaml\Yaml; +use Throwable; +use function array_map; +use function array_merge; +use function array_walk; +use function class_exists; +use function dirname; +use function file_exists; +use function in_array; +use function interface_exists; +use function is_array; +use function is_dir; +use function is_string; +use function realpath; +use function str_replace; +use function strpos; +use function strtr; +use function trigger_error; +use function ucwords; +use function usort; class DrupalAutoloader { @@ -68,7 +92,7 @@ public function register(Container $container): void $drupalRoot = $finder->getDrupalRoot(); $drupalVendorRoot = $finder->getVendorDir(); if (! (bool) $drupalRoot || ! (bool) $drupalVendorRoot) { - throw new \RuntimeException("Unable to detect Drupal at {$drupalParams['drupal_root']}"); + throw new RuntimeException("Unable to detect Drupal at {$drupalParams['drupal_root']}"); } $this->drupalRoot = $drupalRoot; @@ -142,11 +166,11 @@ public function register(Container $container): void } } - if (class_exists(\Drush\Drush::class)) { - $reflect = new \ReflectionClass(\Drush\Drush::class); + if (class_exists(Drush::class)) { + $reflect = new ReflectionClass(Drush::class); if ($reflect->getFileName() !== false) { $levels = 2; - if (\Drush\Drush::getMajorVersion() < 9) { + if (Drush::getMajorVersion() < 9) { $levels = 3; } $drushDir = dirname($reflect->getFileName(), $levels); @@ -200,9 +224,9 @@ class: Drupal\jsonapi\Routing\JsonApiParamEnhancer $service_map = $container->getByType(ServiceMap::class); $service_map->setDrupalServices($this->serviceMap); - if (interface_exists(\PHPUnit\Framework\Test::class) + if (interface_exists(Test::class) && class_exists('Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter')) { - \Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter::mutateTestBase($this->autoloader); + ClassWriter::mutateTestBase($this->autoloader); } $extension_map = $container->getByType(ExtensionMap::class); @@ -307,7 +331,7 @@ protected function loadExtension(Extension $extension): void { try { $extension->load(); - } catch (\Throwable $e) { + } catch (Throwable $e) { // Something prevented the extension file from loading. // This can happen when drupal_get_path or drupal_get_filename are used outside of the scope of a function. } @@ -321,7 +345,7 @@ protected function loadAndCatchErrors(string $path): void $path = str_replace(dirname($this->drupalRoot) . '/', '', $path); // This can happen when drupal_get_path or drupal_get_filename are used outside the scope of a function. @trigger_error("$path invoked the Drupal container outside of the scope of a function or class method. It was not loaded.", E_USER_WARNING); - } catch (\Throwable $e) { + } catch (Throwable $e) { $path = str_replace(dirname($this->drupalRoot) . '/', '', $path); // Something prevented the extension file from loading. @trigger_error("$path failed loading due to {$e->getMessage()}", E_USER_WARNING); diff --git a/src/Drupal/DrupalServiceDefinition.php b/src/Drupal/DrupalServiceDefinition.php index 11912f1a..cf8cfd00 100644 --- a/src/Drupal/DrupalServiceDefinition.php +++ b/src/Drupal/DrupalServiceDefinition.php @@ -6,6 +6,8 @@ use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use function count; +use function str_replace; class DrupalServiceDefinition { diff --git a/src/Drupal/Extension.php b/src/Drupal/Extension.php index bc336c6b..c43c6370 100644 --- a/src/Drupal/Extension.php +++ b/src/Drupal/Extension.php @@ -2,7 +2,14 @@ namespace mglaman\PHPStanDrupal\Drupal; +use RuntimeException; use Symfony\Component\Yaml\Yaml; +use function explode; +use function file_get_contents; +use function is_array; +use function sprintf; +use function strpos; +use function trim; /** * Defines an extension (file) object. @@ -190,7 +197,7 @@ public function load(): bool */ public function getDependencies(): array { - if (\is_array($this->dependencies)) { + if (is_array($this->dependencies)) { return $this->dependencies; } @@ -205,12 +212,12 @@ public function getDependencies(): array // @see \Drupal\Core\Extension\Dependency::createFromString(). foreach ($dependencies as $dependency) { - if (\strpos($dependency, ':') !== false) { - [, $dependency] = \explode(':', $dependency); + if (strpos($dependency, ':') !== false) { + [, $dependency] = explode(':', $dependency); } - $parts = \explode('(', $dependency, 2); - $this->dependencies[] = \trim($parts[0]); + $parts = explode('(', $dependency, 2); + $this->dependencies[] = trim($parts[0]); } return $this->dependencies; @@ -218,13 +225,13 @@ public function getDependencies(): array private function parseInfo(): array { - if (\is_array($this->info)) { + if (is_array($this->info)) { return $this->info; } - $infoContent = \file_get_contents(\sprintf('%s/%s', $this->root, $this->getPathname())); + $infoContent = file_get_contents(sprintf('%s/%s', $this->root, $this->getPathname())); if (false === $infoContent) { - throw new \RuntimeException(\sprintf('Cannot read "%s', $this->getPathname())); + throw new RuntimeException(sprintf('Cannot read "%s', $this->getPathname())); } return $this->info = Yaml::parse($infoContent); diff --git a/src/Drupal/ExtensionDiscovery.php b/src/Drupal/ExtensionDiscovery.php index 4d9ebb19..0d65a845 100644 --- a/src/Drupal/ExtensionDiscovery.php +++ b/src/Drupal/ExtensionDiscovery.php @@ -2,6 +2,19 @@ namespace mglaman\PHPStanDrupal\Drupal; +use FilesystemIterator; +use mglaman\PHPStanDrupal\Drupal\Extension; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; +use function array_filter; +use function array_flip; +use function array_multisort; +use function dirname; +use function file_exists; +use function is_dir; +use function preg_match; +use function strpos; + class ExtensionDiscovery { @@ -207,7 +220,7 @@ protected function filterByProfileDirectories(array $all_files) return $all_files; } - return array_filter($all_files, function (\mglaman\PHPStanDrupal\Drupal\Extension $file) : bool { + return array_filter($all_files, function (Extension $file) : bool { if (strpos($file->subpath, 'profiles') !== 0) { // This extension doesn't belong to a profile, ignore it. return true; @@ -332,11 +345,11 @@ protected function scanDirectory($dir): array // symlinks (to allow extensions to be linked from elsewhere), and return // the RecursiveDirectoryIterator instance to have access to getSubPath(), // since SplFileInfo does not support relative paths. - $flags = \FilesystemIterator::UNIX_PATHS; - $flags |= \FilesystemIterator::SKIP_DOTS; - $flags |= \FilesystemIterator::FOLLOW_SYMLINKS; - $flags |= \FilesystemIterator::CURRENT_AS_SELF; - $directory_iterator = new \RecursiveDirectoryIterator($absolute_dir, $flags); + $flags = FilesystemIterator::UNIX_PATHS; + $flags |= FilesystemIterator::SKIP_DOTS; + $flags |= FilesystemIterator::FOLLOW_SYMLINKS; + $flags |= FilesystemIterator::CURRENT_AS_SELF; + $directory_iterator = new RecursiveDirectoryIterator($absolute_dir, $flags); // Allow directories specified in settings.php to be ignored. You can use // this to not check for files in common special-purpose directories. For @@ -352,11 +365,11 @@ protected function scanDirectory($dir): array // The actual recursive filesystem scan is only invoked by instantiating the // RecursiveIteratorIterator. - $iterator = new \RecursiveIteratorIterator( + $iterator = new RecursiveIteratorIterator( $filter, - \RecursiveIteratorIterator::LEAVES_ONLY, + RecursiveIteratorIterator::LEAVES_ONLY, // Suppress filesystem errors in case a directory cannot be accessed. - \RecursiveIteratorIterator::CATCH_GET_CHILD + RecursiveIteratorIterator::CATCH_GET_CHILD ); foreach ($iterator as $key => $fileinfo) { diff --git a/src/Drupal/ExtensionMap.php b/src/Drupal/ExtensionMap.php index d51f4f7d..819c23b0 100644 --- a/src/Drupal/ExtensionMap.php +++ b/src/Drupal/ExtensionMap.php @@ -2,6 +2,10 @@ namespace mglaman\PHPStanDrupal\Drupal; +use function array_combine; +use function array_map; +use function is_array; + final class ExtensionMap { /** @var array */ diff --git a/src/Drupal/RecursiveExtensionFilterIterator.php b/src/Drupal/RecursiveExtensionFilterIterator.php index 239c146f..94cd90fb 100644 --- a/src/Drupal/RecursiveExtensionFilterIterator.php +++ b/src/Drupal/RecursiveExtensionFilterIterator.php @@ -2,6 +2,12 @@ namespace mglaman\PHPStanDrupal\Drupal; +use RecursiveFilterIterator; +use RecursiveIterator; +use function array_merge; +use function in_array; +use function substr; + /** * Filters a RecursiveDirectoryIterator to discover extensions. * @@ -9,7 +15,7 @@ * * @method bool isDir() */ -class RecursiveExtensionFilterIterator extends \RecursiveFilterIterator +class RecursiveExtensionFilterIterator extends RecursiveFilterIterator { /** @@ -65,7 +71,7 @@ class RecursiveExtensionFilterIterator extends \RecursiveFilterIterator * (optional) Add to the blacklist of directories that should be filtered * out during the iteration. */ - public function __construct(\RecursiveIterator $iterator, array $blacklist = []) + public function __construct(RecursiveIterator $iterator, array $blacklist = []) { parent::__construct($iterator); $this->blacklist = array_merge($this->blacklist, $blacklist); @@ -74,7 +80,7 @@ public function __construct(\RecursiveIterator $iterator, array $blacklist = []) /** * {@inheritdoc} */ - public function getChildren(): \RecursiveFilterIterator + public function getChildren(): RecursiveFilterIterator { $filter = parent::getChildren(); if ($filter instanceof self) { diff --git a/src/Drupal/ServiceMap.php b/src/Drupal/ServiceMap.php index c6368d60..b27c5e4b 100644 --- a/src/Drupal/ServiceMap.php +++ b/src/Drupal/ServiceMap.php @@ -2,6 +2,8 @@ namespace mglaman\PHPStanDrupal\Drupal; +use function class_exists; + class ServiceMap { /** @var DrupalServiceDefinition[] */ diff --git a/src/Reflection/EntityFieldMethodsViaMagicReflectionExtension.php b/src/Reflection/EntityFieldMethodsViaMagicReflectionExtension.php index a964a12a..d177ac62 100644 --- a/src/Reflection/EntityFieldMethodsViaMagicReflectionExtension.php +++ b/src/Reflection/EntityFieldMethodsViaMagicReflectionExtension.php @@ -6,6 +6,7 @@ use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\MethodsClassReflectionExtension; use PHPStan\Type\ObjectType; +use function array_key_exists; /** * Allows some common methods on fields. diff --git a/src/Reflection/EntityFieldReflection.php b/src/Reflection/EntityFieldReflection.php index 9693bc19..dd6c45ac 100644 --- a/src/Reflection/EntityFieldReflection.php +++ b/src/Reflection/EntityFieldReflection.php @@ -4,6 +4,7 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\PropertyReflection; +use PHPStan\TrinaryLogic; use PHPStan\Type\MixedType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -116,13 +117,13 @@ public function getDocComment(): ?string return null; } - public function isDeprecated(): \PHPStan\TrinaryLogic + public function isDeprecated(): TrinaryLogic { - return \PHPStan\TrinaryLogic::createNo(); + return TrinaryLogic::createNo(); } - public function isInternal(): \PHPStan\TrinaryLogic + public function isInternal(): TrinaryLogic { - return \PHPStan\TrinaryLogic::createNo(); + return TrinaryLogic::createNo(); } } diff --git a/src/Reflection/EntityFieldsViaMagicReflectionExtension.php b/src/Reflection/EntityFieldsViaMagicReflectionExtension.php index 61209a79..5261e926 100644 --- a/src/Reflection/EntityFieldsViaMagicReflectionExtension.php +++ b/src/Reflection/EntityFieldsViaMagicReflectionExtension.php @@ -2,11 +2,13 @@ namespace mglaman\PHPStanDrupal\Reflection; +use LogicException; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\PropertiesClassReflectionExtension; use PHPStan\Reflection\PropertyReflection; use PHPStan\TrinaryLogic; use PHPStan\Type\ObjectType; +use function array_key_exists; /** * Allows field access via magic methods @@ -58,7 +60,7 @@ public function getProperty(ClassReflection $classReflection, string $propertyNa return new FieldItemListPropertyReflection($classReflection, $propertyName); } - throw new \LogicException($classReflection->getName() . "::$propertyName should be handled earlier."); + throw new LogicException($classReflection->getName() . "::$propertyName should be handled earlier."); } public static function classObjectIsSuperOfInterface(string $name, ObjectType $interfaceObject) : TrinaryLogic diff --git a/src/Reflection/FieldItemListPropertyReflection.php b/src/Reflection/FieldItemListPropertyReflection.php index 55fbe343..53583b43 100644 --- a/src/Reflection/FieldItemListPropertyReflection.php +++ b/src/Reflection/FieldItemListPropertyReflection.php @@ -4,10 +4,12 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\PropertyReflection; +use PHPStan\TrinaryLogic; use PHPStan\Type\NullType; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use function in_array; /** * Allows field access via magic methods @@ -111,9 +113,9 @@ public function getDocComment(): ?string return null; } - public function isDeprecated(): \PHPStan\TrinaryLogic + public function isDeprecated(): TrinaryLogic { - return \PHPStan\TrinaryLogic::createNo(); + return TrinaryLogic::createNo(); } public function getDeprecatedDescription(): ?string @@ -121,8 +123,8 @@ public function getDeprecatedDescription(): ?string return null; } - public function isInternal(): \PHPStan\TrinaryLogic + public function isInternal(): TrinaryLogic { - return \PHPStan\TrinaryLogic::createNo(); + return TrinaryLogic::createNo(); } } diff --git a/src/Rules/Classes/ClassExtendsInternalClassRule.php b/src/Rules/Classes/ClassExtendsInternalClassRule.php index bba5dc1d..3d6ee5d2 100644 --- a/src/Rules/Classes/ClassExtendsInternalClassRule.php +++ b/src/Rules/Classes/ClassExtendsInternalClassRule.php @@ -9,6 +9,7 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use function sprintf; class ClassExtendsInternalClassRule implements Rule { @@ -70,9 +71,9 @@ public function processNode(Node $node, Scope $scope): array private function buildError(?string $currentClassName, string $extendedClassName): RuleErrorBuilder { - return RuleErrorBuilder::message(\sprintf( + return RuleErrorBuilder::message(sprintf( '%s extends @internal class %s.', - $currentClassName !== null ? \sprintf('Class %s', $currentClassName) : 'Anonymous class', + $currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class', $extendedClassName )); } diff --git a/src/Rules/Classes/PluginManagerInspectionRule.php b/src/Rules/Classes/PluginManagerInspectionRule.php index b624ad60..98871f9d 100644 --- a/src/Rules/Classes/PluginManagerInspectionRule.php +++ b/src/Rules/Classes/PluginManagerInspectionRule.php @@ -7,6 +7,7 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; use PHPStan\Type\ObjectType; +use function sprintf; /** * @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Class_> diff --git a/src/Rules/Deprecations/AccessDeprecatedConstant.php b/src/Rules/Deprecations/AccessDeprecatedConstant.php index 32568367..49c0d7d7 100644 --- a/src/Rules/Deprecations/AccessDeprecatedConstant.php +++ b/src/Rules/Deprecations/AccessDeprecatedConstant.php @@ -2,12 +2,17 @@ namespace mglaman\PHPStanDrupal\Rules\Deprecations; +use Drupal; use mglaman\PHPStanDrupal\Internal\DeprecatedScopeCheck; use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; +use PHPStan\Rules\Rule; +use function array_merge; +use function explode; +use function sprintf; -class AccessDeprecatedConstant implements \PHPStan\Rules\Rule +class AccessDeprecatedConstant implements Rule { /** @var ReflectionProvider */ private $reflectionProvider; @@ -88,7 +93,7 @@ public function processNode(Node $node, Scope $scope): array 'USER_REGISTER_VISITORS' => 'Deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use \Drupal\user\UserInterface::REGISTER_VISITORS instead.', 'USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL' => 'Deprecated in drupal:8.3.0 and is removed from drupal:9.0.0. Use \Drupal\user\UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL instead.', ]; - [$major, $minor] = explode('.', \Drupal::VERSION, 3); + [$major, $minor] = explode('.', Drupal::VERSION, 3); if ($major === '9') { if ((int) $minor >= 1) { $deprecatedConstants = array_merge($deprecatedConstants, [ diff --git a/src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php b/src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php index 30f99ce5..e107d1b2 100644 --- a/src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php +++ b/src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php @@ -10,6 +10,7 @@ use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantStringType; use PHPStan\Type\ObjectType; +use function count; final class ConditionManagerCreateInstanceContextConfigurationRule implements Rule { diff --git a/src/Rules/Deprecations/ConfigEntityConfigExportRule.php b/src/Rules/Deprecations/ConfigEntityConfigExportRule.php index 3b17fc73..1c4bcf5a 100644 --- a/src/Rules/Deprecations/ConfigEntityConfigExportRule.php +++ b/src/Rules/Deprecations/ConfigEntityConfigExportRule.php @@ -8,6 +8,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\Reflection\ClassReflection; use PHPStan\ShouldNotHappenException; +use function preg_match; final class ConfigEntityConfigExportRule extends DeprecatedAnnotationsRuleBase { diff --git a/src/Rules/Deprecations/DeprecatedHookImplementation.php b/src/Rules/Deprecations/DeprecatedHookImplementation.php index 4b2d3f02..aa4db700 100644 --- a/src/Rules/Deprecations/DeprecatedHookImplementation.php +++ b/src/Rules/Deprecations/DeprecatedHookImplementation.php @@ -9,6 +9,10 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use function basename; +use function explode; +use function strlen; +use function substr_replace; class DeprecatedHookImplementation implements Rule { diff --git a/src/Rules/Deprecations/PluginAnnotationContextDefinitionsRule.php b/src/Rules/Deprecations/PluginAnnotationContextDefinitionsRule.php index cb3e4882..814ae8e8 100644 --- a/src/Rules/Deprecations/PluginAnnotationContextDefinitionsRule.php +++ b/src/Rules/Deprecations/PluginAnnotationContextDefinitionsRule.php @@ -6,6 +6,7 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\ShouldNotHappenException; +use function preg_match; final class PluginAnnotationContextDefinitionsRule extends DeprecatedAnnotationsRuleBase { diff --git a/src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php b/src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php index 333a8e8a..8070f0dc 100644 --- a/src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php +++ b/src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php @@ -2,6 +2,7 @@ namespace mglaman\PHPStanDrupal\Rules\Deprecations; +use Drupal; use Drupal\Core\Routing\RouteObjectInterface; use mglaman\PHPStanDrupal\Internal\DeprecatedScopeCheck; use PhpParser\Node; @@ -9,6 +10,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; +use Symfony\Cmf\Component\Routing\RouteObjectInterface as SymfonyRouteObjectInterface; +use function sprintf; final class SymfonyCmfRouteObjectInterfaceConstantsRule implements Rule { @@ -36,11 +39,11 @@ public function processNode(Node $node, Scope $scope): array if (DeprecatedScopeCheck::inDeprecatedScope($scope)) { return []; } - [$major, $minor] = explode('.', \Drupal::VERSION, 3); + [$major, $minor] = explode('.', Drupal::VERSION, 3); if ($major !== '9' && (int) $minor > 1) { return []; } - $cmfRouteObjectInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteObjectInterface::class); + $cmfRouteObjectInterfaceType = new ObjectType(SymfonyRouteObjectInterface::class); if (!$classType->isSuperTypeOf($cmfRouteObjectInterfaceType)->yes()) { return []; } diff --git a/src/Rules/Deprecations/SymfonyCmfRoutingInClassMethodSignatureRule.php b/src/Rules/Deprecations/SymfonyCmfRoutingInClassMethodSignatureRule.php index 1bb4e75d..92cd843e 100644 --- a/src/Rules/Deprecations/SymfonyCmfRoutingInClassMethodSignatureRule.php +++ b/src/Rules/Deprecations/SymfonyCmfRoutingInClassMethodSignatureRule.php @@ -2,6 +2,7 @@ namespace mglaman\PHPStanDrupal\Rules\Deprecations; +use Drupal; use mglaman\PHPStanDrupal\Internal\DeprecatedScopeCheck; use PhpParser\Node; use PHPStan\Analyser\Scope; @@ -10,6 +11,11 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; +use Symfony\Cmf\Component\Routing\LazyRouteCollection; +use Symfony\Cmf\Component\Routing\RouteObjectInterface; +use Symfony\Cmf\Component\Routing\RouteProviderInterface; +use function explode; +use function sprintf; final class SymfonyCmfRoutingInClassMethodSignatureRule implements Rule { @@ -25,15 +31,15 @@ public function processNode(Node $node, Scope $scope): array if (DeprecatedScopeCheck::inDeprecatedScope($scope)) { return []; } - [$major, $minor] = explode('.', \Drupal::VERSION, 3); + [$major, $minor] = explode('.', Drupal::VERSION, 3); if ($major !== '9' || (int) $minor < 1) { return []; } $method = $node->getMethodReflection(); - $cmfRouteObjectInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteObjectInterface::class); - $cmfRouteProviderInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteProviderInterface::class); - $cmfLazyRouteCollectionType = new ObjectType(\Symfony\Cmf\Component\Routing\LazyRouteCollection::class); + $cmfRouteObjectInterfaceType = new ObjectType(RouteObjectInterface::class); + $cmfRouteProviderInterfaceType = new ObjectType(RouteProviderInterface::class); + $cmfLazyRouteCollectionType = new ObjectType(LazyRouteCollection::class); $methodSignature = ParametersAcceptorSelector::selectSingle($method->getVariants()); diff --git a/src/Rules/Drupal/Coder/DiscouragedFunctionsRule.php b/src/Rules/Drupal/Coder/DiscouragedFunctionsRule.php index d967df21..fddacf3c 100644 --- a/src/Rules/Drupal/Coder/DiscouragedFunctionsRule.php +++ b/src/Rules/Drupal/Coder/DiscouragedFunctionsRule.php @@ -6,6 +6,9 @@ use PhpParser\Node\Expr\FuncCall; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use function in_array; +use function sprintf; +use function strtolower; /** * Based on Drupal_Sniffs_Functions_DiscouragedFunctionsSniff. diff --git a/src/Rules/Drupal/LoadIncludeBase.php b/src/Rules/Drupal/LoadIncludeBase.php index 054381a7..08375375 100644 --- a/src/Rules/Drupal/LoadIncludeBase.php +++ b/src/Rules/Drupal/LoadIncludeBase.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PHPStan\Analyser\Scope; use PHPStan\Rules\Rule; +use function count; abstract class LoadIncludeBase implements Rule { diff --git a/src/Rules/Drupal/LoadIncludes.php b/src/Rules/Drupal/LoadIncludes.php index 9eed4cad..2164a7ed 100644 --- a/src/Rules/Drupal/LoadIncludes.php +++ b/src/Rules/Drupal/LoadIncludes.php @@ -7,6 +7,10 @@ use PHPStan\Analyser\Scope; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; +use Throwable; +use function count; +use function is_file; +use function sprintf; class LoadIncludes extends LoadIncludeBase { @@ -27,7 +31,7 @@ public function processNode(Node $node, Scope $scope): array return []; } $args = $node->getArgs(); - if (\count($args) < 2) { + if (count($args) < 2) { return []; } $type = $scope->getType($node->var); @@ -72,7 +76,7 @@ public function processNode(Node $node, Scope $scope): array ->line($node->getStartLine()) ->build() ]; - } catch (\Throwable $e) { + } catch (Throwable $e) { return [ RuleErrorBuilder::message(sprintf( 'A file could not be loaded from %s::loadInclude', diff --git a/src/Rules/Drupal/ModuleLoadInclude.php b/src/Rules/Drupal/ModuleLoadInclude.php index 809f5409..9a865e92 100644 --- a/src/Rules/Drupal/ModuleLoadInclude.php +++ b/src/Rules/Drupal/ModuleLoadInclude.php @@ -3,8 +3,13 @@ namespace mglaman\PHPStanDrupal\Rules\Drupal; use PhpParser\Node; +use PhpParser\Node\Name; use PHPStan\Analyser\Scope; use PHPStan\Rules\RuleErrorBuilder; +use Throwable; +use function count; +use function is_file; +use function sprintf; /** * Handles module_load_include dynamic file loading. @@ -23,7 +28,7 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { assert($node instanceof Node\Expr\FuncCall); - if (!$node->name instanceof \PhpParser\Node\Name) { + if (!$node->name instanceof Name) { return []; } $name = (string) $node->name; @@ -31,7 +36,7 @@ public function processNode(Node $node, Scope $scope): array return []; } $args = $node->getArgs(); - if (\count($args) < 2) { + if (count($args) < 2) { return []; } @@ -63,7 +68,7 @@ public function processNode(Node $node, Scope $scope): array ->line($node->getStartLine()) ->build() ]; - } catch (\Throwable $e) { + } catch (Throwable $e) { return [ RuleErrorBuilder::message('A file could not be loaded from module_load_include') ->line($node->getStartLine()) diff --git a/src/Rules/Drupal/PluginManager/PluginManagerSetsCacheBackendRule.php b/src/Rules/Drupal/PluginManager/PluginManagerSetsCacheBackendRule.php index 22b350da..e4a2911d 100644 --- a/src/Rules/Drupal/PluginManager/PluginManagerSetsCacheBackendRule.php +++ b/src/Rules/Drupal/PluginManager/PluginManagerSetsCacheBackendRule.php @@ -5,7 +5,12 @@ use PhpParser\Node; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Analyser\Scope; +use PHPStan\ShouldNotHappenException; use PHPStan\Type\Type; +use function array_map; +use function count; +use function sprintf; +use function strpos; class PluginManagerSetsCacheBackendRule extends AbstractPluginManagerRule { @@ -25,7 +30,7 @@ public function processNode(Node $node, Scope $scope): array assert($node instanceof Node\Stmt\ClassMethod); if (!$scope->isInClass()) { - throw new \PHPStan\ShouldNotHappenException(); + throw new ShouldNotHappenException(); } if ($scope->isInTrait()) { diff --git a/src/Rules/Drupal/RenderCallbackRule.php b/src/Rules/Drupal/RenderCallbackRule.php index c93153e5..66930de3 100644 --- a/src/Rules/Drupal/RenderCallbackRule.php +++ b/src/Rules/Drupal/RenderCallbackRule.php @@ -27,6 +27,14 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use function array_map; +use function array_merge; +use function class_exists; +use function count; +use function explode; +use function preg_match; +use function sprintf; +use function substr_count; final class RenderCallbackRule implements Rule { diff --git a/src/Rules/Drupal/RequestStackGetMainRequestRule.php b/src/Rules/Drupal/RequestStackGetMainRequestRule.php index 46d98439..fd630c85 100644 --- a/src/Rules/Drupal/RequestStackGetMainRequestRule.php +++ b/src/Rules/Drupal/RequestStackGetMainRequestRule.php @@ -2,6 +2,7 @@ namespace mglaman\PHPStanDrupal\Rules\Drupal; +use Drupal; use Drupal\Core\Http\RequestStack as DrupalRequestStack; use mglaman\PHPStanDrupal\Internal\DeprecatedScopeCheck; use PhpParser\Node; @@ -10,6 +11,8 @@ use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; use Symfony\Component\HttpFoundation\RequestStack as SymfonyRequestStack; +use function explode; +use function sprintf; final class RequestStackGetMainRequestRule implements Rule { @@ -25,7 +28,7 @@ public function processNode(Node $node, Scope $scope): array if (DeprecatedScopeCheck::inDeprecatedScope($scope)) { return []; } - [$major, $minor] = explode('.', \Drupal::VERSION, 3); + [$major, $minor] = explode('.', Drupal::VERSION, 3); // Only valid for 9.3 -> 9.5. Deprecated in Drupal 10. if ($major !== '9' || (int) $minor < 3) { return []; diff --git a/src/Rules/Drupal/TestClassesProtectedPropertyModulesRule.php b/src/Rules/Drupal/TestClassesProtectedPropertyModulesRule.php index e30ca422..19d3770b 100644 --- a/src/Rules/Drupal/TestClassesProtectedPropertyModulesRule.php +++ b/src/Rules/Drupal/TestClassesProtectedPropertyModulesRule.php @@ -10,6 +10,8 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPUnit\Framework\TestCase; +use function in_array; +use function sprintf; class TestClassesProtectedPropertyModulesRule implements Rule { diff --git a/src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php b/src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php index 56cb537a..581cd589 100644 --- a/src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php +++ b/src/Rules/Drupal/Tests/BrowserTestBaseDefaultThemeRule.php @@ -8,6 +8,12 @@ use PHPStan\Rules\RuleErrorBuilder; use PHPStan\Type\ObjectType; use PHPStan\Type\TypeCombinator; +use PHPUnit\Framework\Test; +use function count; +use function in_array; +use function interface_exists; +use function method_exists; +use function substr_compare; final class BrowserTestBaseDefaultThemeRule implements Rule { @@ -19,7 +25,7 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { - if (!interface_exists(\PHPUnit\Framework\Test::class)) { + if (!interface_exists(Test::class)) { return []; } assert($node instanceof Node\Stmt\Class_); diff --git a/src/Type/ContainerDynamicReturnTypeExtension.php b/src/Type/ContainerDynamicReturnTypeExtension.php index 96869b64..c556712b 100644 --- a/src/Type/ContainerDynamicReturnTypeExtension.php +++ b/src/Type/ContainerDynamicReturnTypeExtension.php @@ -13,6 +13,8 @@ use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use Symfony\Component\DependencyInjection\ContainerInterface; +use function count; +use function in_array; class ContainerDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/DrupalClassResolverDynamicReturnTypeExtension.php b/src/Type/DrupalClassResolverDynamicReturnTypeExtension.php index 8db290e7..b34158be 100644 --- a/src/Type/DrupalClassResolverDynamicReturnTypeExtension.php +++ b/src/Type/DrupalClassResolverDynamicReturnTypeExtension.php @@ -10,6 +10,7 @@ use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\Type; +use function count; class DrupalClassResolverDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { @@ -38,7 +39,7 @@ public function getTypeFromMethodCall( MethodCall $methodCall, Scope $scope ): Type { - if (0 === \count($methodCall->getArgs())) { + if (0 === count($methodCall->getArgs())) { return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); } diff --git a/src/Type/DrupalClassResolverDynamicStaticReturnTypeExtension.php b/src/Type/DrupalClassResolverDynamicStaticReturnTypeExtension.php index d28132fb..d66bf66b 100644 --- a/src/Type/DrupalClassResolverDynamicStaticReturnTypeExtension.php +++ b/src/Type/DrupalClassResolverDynamicStaticReturnTypeExtension.php @@ -2,6 +2,7 @@ namespace mglaman\PHPStanDrupal\Type; +use Drupal; use Drupal\Core\DependencyInjection\ClassResolverInterface; use mglaman\PHPStanDrupal\Drupal\ServiceMap; use PhpParser\Node\Expr\StaticCall; @@ -10,6 +11,7 @@ use PHPStan\Type\DynamicStaticMethodReturnTypeExtension; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use function count; class DrupalClassResolverDynamicStaticReturnTypeExtension implements DynamicStaticMethodReturnTypeExtension { @@ -25,7 +27,7 @@ public function __construct(ServiceMap $serviceMap) public function getClass(): string { - return \Drupal::class; + return Drupal::class; } public function isStaticMethodSupported(MethodReflection $methodReflection): bool @@ -38,7 +40,7 @@ public function getTypeFromStaticMethodCall( StaticCall $methodCall, Scope $scope ): Type { - if (0 === \count($methodCall->getArgs())) { + if (0 === count($methodCall->getArgs())) { return new ObjectType(ClassResolverInterface::class); } diff --git a/src/Type/DrupalClassResolverReturnType.php b/src/Type/DrupalClassResolverReturnType.php index 9099fce7..8884cb04 100644 --- a/src/Type/DrupalClassResolverReturnType.php +++ b/src/Type/DrupalClassResolverReturnType.php @@ -12,6 +12,7 @@ use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use function count; final class DrupalClassResolverReturnType { diff --git a/src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php b/src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php index 51397e46..587d086b 100644 --- a/src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php +++ b/src/Type/DrupalStaticEntityQueryDynamicReturnTypeExtension.php @@ -2,6 +2,7 @@ namespace mglaman\PHPStanDrupal\Type; +use Drupal; use Drupal\Core\Config\Entity\ConfigEntityStorageInterface; use Drupal\Core\Entity\ContentEntityStorageInterface; use mglaman\PHPStanDrupal\Drupal\EntityDataRepository; @@ -31,7 +32,7 @@ public function __construct(EntityDataRepository $entityDataRepository) public function getClass(): string { - return \Drupal::class; + return Drupal::class; } public function isStaticMethodSupported(MethodReflection $methodReflection): bool diff --git a/src/Type/EntityAccessControlHandlerReturnTypeExtension.php b/src/Type/EntityAccessControlHandlerReturnTypeExtension.php index 20c728a9..066fe3b0 100644 --- a/src/Type/EntityAccessControlHandlerReturnTypeExtension.php +++ b/src/Type/EntityAccessControlHandlerReturnTypeExtension.php @@ -11,6 +11,8 @@ use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; +use function count; +use function in_array; final class EntityAccessControlHandlerReturnTypeExtension implements DynamicMethodReturnTypeExtension { @@ -31,13 +33,13 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method $args = $methodCall->getArgs(); $arg = null; - if ($methodReflection->getName() === 'access' && \count($args) === 4) { + if ($methodReflection->getName() === 'access' && count($args) === 4) { $arg = $args[3]; } - if ($methodReflection->getName() === 'createAccess' && \count($args) === 4) { + if ($methodReflection->getName() === 'createAccess' && count($args) === 4) { $arg = $args[3]; } - if ($methodReflection->getName() === 'fieldAccess' && \count($args) === 5) { + if ($methodReflection->getName() === 'fieldAccess' && count($args) === 5) { $arg = $args[4]; } diff --git a/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php b/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php index cdc3b9d8..a19aadca 100644 --- a/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php +++ b/src/Type/EntityQuery/EntityQueryDynamicReturnTypeExtension.php @@ -13,6 +13,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; use PHPStan\Type\Type; +use function in_array; class EntityQueryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { diff --git a/src/Type/EntityQuery/EntityQueryType.php b/src/Type/EntityQuery/EntityQueryType.php index cebd5131..f8952bd4 100644 --- a/src/Type/EntityQuery/EntityQueryType.php +++ b/src/Type/EntityQuery/EntityQueryType.php @@ -5,6 +5,7 @@ namespace mglaman\PHPStanDrupal\Type\EntityQuery; use PHPStan\Type\ObjectType; +use function implode; class EntityQueryType extends ObjectType { diff --git a/src/Type/EntityStorage/EntityStorageDynamicReturnTypeExtension.php b/src/Type/EntityStorage/EntityStorageDynamicReturnTypeExtension.php index 78c0fe51..08b4057c 100644 --- a/src/Type/EntityStorage/EntityStorageDynamicReturnTypeExtension.php +++ b/src/Type/EntityStorage/EntityStorageDynamicReturnTypeExtension.php @@ -14,7 +14,9 @@ use PHPStan\Type\IntegerType; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; +use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; +use function in_array; class EntityStorageDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { @@ -36,7 +38,7 @@ public function getClass(): string public function isMethodSupported(MethodReflection $methodReflection): bool { - return \in_array( + return in_array( $methodReflection->getName(), [ 'create', @@ -53,7 +55,7 @@ public function getTypeFromMethodCall( MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope - ): \PHPStan\Type\Type { + ): Type { $callerType = $scope->getType($methodCall->var); if (!$callerType instanceof ObjectType) { return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); @@ -72,11 +74,11 @@ public function getTypeFromMethodCall( if ($type === null) { return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); } - if (\in_array($methodReflection->getName(), ['load', 'loadUnchanged'], true)) { + if (in_array($methodReflection->getName(), ['load', 'loadUnchanged'], true)) { return TypeCombinator::addNull($type); } - if (\in_array($methodReflection->getName(), ['loadMultiple', 'loadByProperties'], true)) { + if (in_array($methodReflection->getName(), ['loadMultiple', 'loadByProperties'], true)) { if ((new ObjectType(ConfigEntityStorageInterface::class))->isSuperTypeOf($callerType)->yes()) { return new ArrayType(new StringType(), $type); } diff --git a/src/Type/EntityStorage/GetQueryReturnTypeExtension.php b/src/Type/EntityStorage/GetQueryReturnTypeExtension.php index 1da6f288..b6f8769a 100644 --- a/src/Type/EntityStorage/GetQueryReturnTypeExtension.php +++ b/src/Type/EntityStorage/GetQueryReturnTypeExtension.php @@ -14,6 +14,8 @@ use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; +use function in_array; final class GetQueryReturnTypeExtension implements DynamicMethodReturnTypeExtension { @@ -35,7 +37,7 @@ public function getTypeFromMethodCall( MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope - ): \PHPStan\Type\Type { + ): Type { $returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); if (!$returnType instanceof ObjectType) { return $returnType; diff --git a/src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php b/src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php index 9217cc23..ae22ca9b 100644 --- a/src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php +++ b/src/Type/EntityTypeManagerGetStorageDynamicReturnTypeExtension.php @@ -13,6 +13,7 @@ use PHPStan\ShouldNotHappenException; use PHPStan\Type\DynamicMethodReturnTypeExtension; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; class EntityTypeManagerGetStorageDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension { @@ -46,7 +47,7 @@ public function getTypeFromMethodCall( MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope - ): \PHPStan\Type\Type { + ): Type { $returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); if (!isset($methodCall->args[0])) { // Parameter is required.