diff --git a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php index 6241130621a..ede8629bba9 100644 --- a/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php +++ b/rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php @@ -253,12 +253,12 @@ private function shouldSkipParameter( // Check if default value is the same $classMethod = $this->astResolver->resolveClassMethodFromCall($node); - if (!$classMethod instanceof ClassMethod) { + if (! $classMethod instanceof ClassMethod) { // is correct scope? return ! $this->argumentAddingScope->isInCorrectScope($node, $argumentAdder); } - if (!isset($classMethod->params[$position])) { + if (! isset($classMethod->params[$position])) { // is correct scope? return ! $this->argumentAddingScope->isInCorrectScope($node, $argumentAdder); } diff --git a/rules/CodingStyle/Application/UseImportsAdder.php b/rules/CodingStyle/Application/UseImportsAdder.php index e6fa15c15ea..776b40af091 100644 --- a/rules/CodingStyle/Application/UseImportsAdder.php +++ b/rules/CodingStyle/Application/UseImportsAdder.php @@ -33,8 +33,12 @@ public function __construct( * @param array $functionUseImportTypes * @return Stmt[] */ - public function addImportsToStmts(FileWithoutNamespace $fileWithoutNamespace, array $stmts, array $useImportTypes, array $functionUseImportTypes): array - { + public function addImportsToStmts( + FileWithoutNamespace $fileWithoutNamespace, + array $stmts, + array $useImportTypes, + array $functionUseImportTypes + ): array { $existingUseImportTypes = $this->usedImportsResolver->resolveForStmts($stmts); $existingFunctionUseImports = $this->usedImportsResolver->resolveFunctionImportsForStmts($stmts); diff --git a/rules/Naming/Naming/UseImportsResolver.php b/rules/Naming/Naming/UseImportsResolver.php index 740d3bf11a6..b151c88518f 100644 --- a/rules/Naming/Naming/UseImportsResolver.php +++ b/rules/Naming/Naming/UseImportsResolver.php @@ -20,40 +20,6 @@ public function __construct( ) { } - private function resolveNamespace(): Namespace_|FileWithoutNamespace|null - { - /** @var File|null $file */ - $file = $this->currentFileProvider->getFile(); - if (! $file instanceof File) { - return null; - } - - $newStmts = $file->getNewStmts(); - - if ($newStmts === []) { - return null; - } - - $namespaces = array_filter($newStmts, static fn(Stmt $stmt): bool => $stmt instanceof Namespace_); - - // multiple namespaces is not supported - if (count($namespaces) > 1) { - return null; - } - - $currentNamespace = current($namespaces); - if ($currentNamespace instanceof Namespace_) { - return $currentNamespace; - } - - $currentStmt = current($newStmts); - if (! $currentStmt instanceof FileWithoutNamespace) { - return null; - } - - return $currentStmt; - } - /** * @return Use_[]|GroupUse[] */ @@ -90,4 +56,38 @@ public function resolvePrefix(Use_|GroupUse $use): string ? $use->prefix . '\\' : ''; } + + private function resolveNamespace(): Namespace_|FileWithoutNamespace|null + { + /** @var File|null $file */ + $file = $this->currentFileProvider->getFile(); + if (! $file instanceof File) { + return null; + } + + $newStmts = $file->getNewStmts(); + + if ($newStmts === []) { + return null; + } + + $namespaces = array_filter($newStmts, static fn (Stmt $stmt): bool => $stmt instanceof Namespace_); + + // multiple namespaces is not supported + if (count($namespaces) > 1) { + return null; + } + + $currentNamespace = current($namespaces); + if ($currentNamespace instanceof Namespace_) { + return $currentNamespace; + } + + $currentStmt = current($newStmts); + if (! $currentStmt instanceof FileWithoutNamespace) { + return null; + } + + return $currentStmt; + } }