From 00d5741aa72dd59447ba1b335b853c9a32f8ef7d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 24 Sep 2023 17:00:34 +0700 Subject: [PATCH] Docblock fix on ShortNameResolver --- packages/Config/RectorConfig.php | 2 +- rules/CodingStyle/ClassNameImport/ShortNameResolver.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/Config/RectorConfig.php b/packages/Config/RectorConfig.php index 78b6f627ebb..75104434adf 100644 --- a/packages/Config/RectorConfig.php +++ b/packages/Config/RectorConfig.php @@ -37,7 +37,7 @@ public function paths(array $paths): void { Assert::allString($paths); - foreach($paths as $path) { + foreach ($paths as $path) { if (str_contains($path, '*')) { continue; } diff --git a/rules/CodingStyle/ClassNameImport/ShortNameResolver.php b/rules/CodingStyle/ClassNameImport/ShortNameResolver.php index 53cd7c2e4df..0aef14fe637 100644 --- a/rules/CodingStyle/ClassNameImport/ShortNameResolver.php +++ b/rules/CodingStyle/ClassNameImport/ShortNameResolver.php @@ -79,8 +79,11 @@ public function resolveShortClassLikeNames(File $file): array { $newStmts = $file->getNewStmts(); - /** @var Namespace_[] $namespaces */ - $namespaces = array_filter($newStmts, static fn (Stmt $stmt): bool => $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace); + /** @var Namespace_[]|FileWithoutNamespace[] $namespaces */ + $namespaces = array_filter( + $newStmts, + static fn (Stmt $stmt): bool => $stmt instanceof Namespace_ || $stmt instanceof FileWithoutNamespace + ); if (count($namespaces) !== 1) { // only handle single namespace nodes return []; @@ -89,7 +92,7 @@ public function resolveShortClassLikeNames(File $file): array $namespace = current($namespaces); /** @var ClassLike[] $classLikes */ - $classLikes = $this->betterNodeFinder->findInstanceOf($namespace, ClassLike::class); + $classLikes = $this->betterNodeFinder->findInstanceOf($namespace->stmts, ClassLike::class); $shortClassLikeNames = []; foreach ($classLikes as $classLike) {