Skip to content

Commit

Permalink
more short functions
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Nov 21, 2024
1 parent 42f3692 commit f73e47c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
12 changes: 5 additions & 7 deletions src/Fixer/AttributeNotation/OrderedAttributesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void

while (null !== $index = $tokens->getNextTokenOfKind($index, [[T_ATTRIBUTE]])) {
/** @var _AttributeItems $elements */
$elements = array_map(function (AttributeAnalysis $attributeAnalysis) use ($tokens): array {
return [
'name' => $this->sortAttributes($tokens, $attributeAnalysis->getStartIndex(), $attributeAnalysis->getAttributes()),
'start' => $attributeAnalysis->getStartIndex(),
'end' => $attributeAnalysis->getEndIndex(),
];
}, AttributeAnalyzer::collect($tokens, $index));
$elements = array_map(fn (AttributeAnalysis $attributeAnalysis): array => [
'name' => $this->sortAttributes($tokens, $attributeAnalysis->getStartIndex(), $attributeAnalysis->getAttributes()),
'start' => $attributeAnalysis->getStartIndex(),
'end' => $attributeAnalysis->getEndIndex(),
], AttributeAnalyzer::collect($tokens, $index));

$endIndex = end($elements)['end'];

Expand Down
10 changes: 4 additions & 6 deletions src/Fixer/Internal/ConfigurableFixerTemplateFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,10 @@ private function applyFixForSrc(\SplFileInfo $file, Tokens $tokens): void

if ('array' === $allowed) {
$default = $option->getDefault();
$getTypes = static function ($values): array {
return array_unique(array_map(
static fn ($val) => \gettype($val),
$values
));
};
$getTypes = static fn ($values): array => array_unique(array_map(
static fn ($val) => \gettype($val),
$values
));
$defaultKeyTypes = $getTypes(array_keys($default));
$defaultValueTypes = $getTypes(array_values($default));
$allowed = \sprintf(
Expand Down
16 changes: 7 additions & 9 deletions tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,13 @@ public function testDataProvidersAreNonPhpVersionConditional(string $testClassNa
$startIndex = $tokens->getNextTokenOfKind($methodIndex, ['{']);
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex);

$versionTokens = array_filter($tokens->findGivenKind(T_STRING, $startIndex, $endIndex), static function (Token $v): bool {
return $v->equalsAny([
[T_STRING, 'PHP_VERSION_ID'],
[T_STRING, 'PHP_MAJOR_VERSION'],
[T_STRING, 'PHP_MINOR_VERSION'],
[T_STRING, 'PHP_RELEASE_VERSION'],
[T_STRING, 'phpversion'],
], false);
});
$versionTokens = array_filter($tokens->findGivenKind(T_STRING, $startIndex, $endIndex), static fn (Token $v): bool => $v->equalsAny([
[T_STRING, 'PHP_VERSION_ID'],
[T_STRING, 'PHP_MAJOR_VERSION'],
[T_STRING, 'PHP_MINOR_VERSION'],
[T_STRING, 'PHP_RELEASE_VERSION'],
[T_STRING, 'phpversion'],
], false));

self::assertCount(
0,
Expand Down
16 changes: 7 additions & 9 deletions tests/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,13 @@ public function testNoDoubleConflictReporting(): void
- "c" with "d", "e" and "f"
- "d" with "g" and "h"
- "e" with "a"',
\Closure::bind(static function (FixerFactory $factory): string {
return $factory->generateConflictMessage([
'a' => ['b'],
'b' => ['a'],
'c' => ['d', 'e', 'f'],
'd' => ['c', 'g', 'h'],
'e' => ['a'],
]);
}, null, FixerFactory::class)($factory),
\Closure::bind(static fn (FixerFactory $factory): string => $factory->generateConflictMessage([
'a' => ['b'],
'b' => ['a'],
'c' => ['d', 'e', 'f'],
'd' => ['c', 'g', 'h'],
'e' => ['a'],
]), null, FixerFactory::class)($factory),
);
}

Expand Down

0 comments on commit f73e47c

Please sign in to comment.