Skip to content

Commit

Permalink
apply cs
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 29, 2023
1 parent 9d85c96 commit 9ff2388
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 38 deletions.
4 changes: 2 additions & 2 deletions rules/Arguments/Rector/ClassMethod/ArgumentAdderRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions rules/CodingStyle/Application/UseImportsAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ public function __construct(
* @param array<FullyQualifiedObjectType|AliasedObjectType> $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);

Expand Down
68 changes: 34 additions & 34 deletions rules/Naming/Naming/UseImportsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 9ff2388

Please sign in to comment.