Skip to content

Commit

Permalink
Skip short class names in UseClassKeywordForClassNameResolutionRector (
Browse files Browse the repository at this point in the history
…#3156)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Dec 5, 2022
1 parent 25dec6b commit f4ff24c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,12 @@ parameters:

- '#Call to static method Webmozart\\Assert\\Assert\:\:allString\(\) with array<string> will always evaluate to true#'

# simple filter
# simple array filters
-
message: '#Use separate function calls with readable variable names#'
path: utils/RuleDocGenerator/PostRectorOutFilter.php
paths:
- utils/RuleDocGenerator/PostRectorOutFilter.php
- rules/CodingStyle/Rector/String_/UseClassKeywordForClassNameResolutionRector.php

# phpdoc node traversing
-
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture;

final class SkipAClosure
{
public function run()
{
return 'Some Closure::needs() to be done';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ public function refactor(Node $node): ?Node
}

$classNames = $this->getExistingClasses($node);
$classNames = $this->filterOurShortClasses($classNames);

if ($classNames === []) {
return $node;
return null;
}

$parts = $this->getParts($node, $classNames);
Expand Down Expand Up @@ -136,4 +138,13 @@ private function createExpressionsToConcat(array $parts): array

return $exprsToConcat;
}

/**
* @param string[] $classNames
* @return string[]
*/
private function filterOurShortClasses(array $classNames): array
{
return array_filter($classNames, static fn (string $className): bool => str_contains($className, '\\'));
}
}

0 comments on commit f4ff24c

Please sign in to comment.