Skip to content

Commit

Permalink
DX: reduce array_filter function usages (#7923)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Apr 7, 2024
1 parent c825d7c commit c7f60ee
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Console/ConfigurationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,10 +832,10 @@ private function resolveFinder(): iterable

$isIntersectionPathMode = self::PATH_MODE_INTERSECTION === $this->options['path-mode'];

$paths = array_filter(array_map(
$paths = array_map(
static fn (string $path) => realpath($path),
$this->getPath()
));
);

if (0 === \count($paths)) {
if ($isIntersectionPathMode) {
Expand Down
4 changes: 2 additions & 2 deletions src/Documentation/RuleSetDocumentationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public function generateRuleSetsDocumentation(RuleSetDescriptionInterface $defin
$warningsHeaderLine = str_repeat('-', \strlen($warningsHeader));
$doc .= "\n\n".implode(
"\n",
array_filter([
[
$warningsHeader,
$warningsHeaderLine,
...$warnings,
])
]
);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Fixer/Import/GlobalNamespaceImportFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$this->fullyQualifyClasses($tokens, $useDeclarations);
}

$newImports = array_filter($newImports);

if (\count($newImports) > 0) {
if (\count($useDeclarations) > 0) {
$useDeclaration = end($useDeclarations);
Expand Down
4 changes: 2 additions & 2 deletions src/Fixer/Import/GroupImportFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function addGroupUseStatements(array $statements, Tokens $tokens): void
$tokens,
$insertIndex,
$useDeclaration,
$this->getNamespaceNameWithSlash($currentUseDeclaration)
rtrim($this->getNamespaceNameWithSlash($currentUseDeclaration), '\\')
);
} else {
$newTokens = [
Expand Down Expand Up @@ -225,7 +225,7 @@ private function createNewGroup(Tokens $tokens, int $insertIndex, NamespaceUseAn
$newTokens[] = new Token([T_WHITESPACE, ' ']);
}

$namespaceParts = array_filter(explode('\\', $currentNamespace));
$namespaceParts = explode('\\', $currentNamespace);

foreach ($namespaceParts as $part) {
$newTokens[] = new Token([T_STRING, $part]);
Expand Down

0 comments on commit c7f60ee

Please sign in to comment.