From a328d370488098bb4127ba26bb18ea1eeb287521 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 7 Jan 2025 00:24:18 +0700 Subject: [PATCH] [Performance] Early return FullyQualifiedObjectType on FQCN on ObjectTypeSpecifier --- rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php index 608707ce97..aa643275ad 100644 --- a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php +++ b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php @@ -44,6 +44,11 @@ public function narrowToFullyQualifiedOrAliasedObjectType( Scope|null $scope, bool $withPreslash = false ): TypeWithClassName | NonExistingObjectType | UnionType | MixedType | TemplateType { + $className = ltrim($objectType->getClassName(), '\\'); + if (str_starts_with($objectType->getClassName(), '\\')) { + return new FullyQualifiedObjectType($className); + } + $uses = $this->useImportsResolver->resolve(); $aliasedObjectType = $this->matchAliasedObjectType($objectType, $uses); @@ -56,11 +61,6 @@ public function narrowToFullyQualifiedOrAliasedObjectType( return $shortenedObjectType; } - $className = ltrim($objectType->getClassName(), '\\'); - if (str_starts_with($objectType->getClassName(), '\\')) { - return new FullyQualifiedObjectType($className); - } - if ($this->reflectionProvider->hasClass($className)) { return new FullyQualifiedObjectType($className); }