Skip to content

Commit

Permalink
DX: add types to anonymous functions (PHP-CS-Fixer#7561)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and danog committed Feb 2, 2024
1 parent 4a9c28f commit 48de1b2
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Fixer/ClassNotation/OrderedTypesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private function isTypeSortable(TypeAnalysis $type): bool
*/
private function collectDisjunctiveNormalFormTypes(string $type): array
{
$types = array_map(static function ($subType) {
$types = array_map(static function (string $subType) {
if (str_starts_with($subType, '(')) {
return explode('&', trim($subType, '()'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
->setAllowedTypes(['array'])
->setAllowedValues([new AllowedValueSubset([self::ELEMENTS_ARRAYS, self::ELEMENTS_ARGUMENTS, self::ELEMENTS_PARAMETERS, self::MATCH_EXPRESSIONS])])
->setDefault([self::ELEMENTS_ARRAYS])
->setNormalizer(static function (Options $options, $value) {
->setNormalizer(static function (Options $options, array $value) {
if (\PHP_VERSION_ID < 8_00_00) { // @TODO: drop condition when PHP 8.0+ is required
foreach ([self::ELEMENTS_PARAMETERS, self::MATCH_EXPRESSIONS] as $option) {
if (\in_array($option, $value, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
(new FixerOptionBuilder('min_line_breaks', 'Minimum line breaks that should exist before namespace declaration.'))
->setAllowedTypes(['int'])
->setDefault(2)
->setNormalizer(static function (Options $options, $value): int {
->setNormalizer(static function (Options $options, int $value): int {
if ($value < 0) {
throw new InvalidFixerConfigurationException(
(new self())->getName(),
Expand All @@ -83,7 +83,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
(new FixerOptionBuilder('max_line_breaks', 'Maximum line breaks that should exist before namespace declaration.'))
->setAllowedTypes(['int'])
->setDefault(2)
->setNormalizer(static function (Options $options, $value): int {
->setNormalizer(static function (Options $options, int $value): int {
if ($value < 0) {
throw new InvalidFixerConfigurationException(
(new self())->getName(),
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
->getOption(),
(new FixerOptionBuilder('replacements', 'A map of tags to replace.'))
->setAllowedTypes(['array'])
->setNormalizer(static function (Options $options, $value): array {
->setNormalizer(static function (Options $options, array $value): array {
$normalizedValue = [];

foreach ($value as $from => $to) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
->setAllowedValues([
new AllowedValueSubset($allowedValues),
])
->setNormalizer(static function (Options $options, $value): array {
->setNormalizer(static function (Options $options, array $value): array {
$normalized = [];

foreach ($value as $annotation) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocOrderFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
return new FixerConfigurationResolver([
(new FixerOptionBuilder('order', 'Sequence in which annotations in PHPDoc should be ordered.'))
->setAllowedTypes(['string[]'])
->setAllowedValues([static function ($order) {
->setAllowedValues([static function (array $order): bool {
if (\count($order) < 2) {
throw new InvalidOptionsException('The option "order" value is invalid. Minimum two tags are required.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocSeparationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void

protected function createConfigurationDefinition(): FixerConfigurationResolverInterface
{
$allowTagToBelongToOnlyOneGroup = static function ($groups) {
$allowTagToBelongToOnlyOneGroup = static function (array $groups): bool {
$tags = [];
foreach ($groups as $groupIndex => $group) {
foreach ($group as $member) {
Expand Down
2 changes: 1 addition & 1 deletion src/Fixer/Phpdoc/PhpdocTagTypeFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn
'var' => 'annotation',
'version' => 'annotation',
])
->setNormalizer(static function (Options $options, $value): array {
->setNormalizer(static function (Options $options, array $value): array {
$normalized = [];

foreach ($value as $tag => $type) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function provideFixCases(): iterable

array_walk(
$cases,
static function (&$case): void {
static function (array &$case): void {
$case[0] = self::generateTest($case[0]);

if (isset($case[1])) {
Expand Down
6 changes: 3 additions & 3 deletions tests/Tokenizer/TokensAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testGetClassyElements(array $expectedElements, string $source):

array_walk(
$expectedElements,
static function (array &$element, $index) use ($tokens): void {
static function (array &$element, int $index) use ($tokens): void {
$element['token'] = $tokens[$index];
ksort($element);
}
Expand Down Expand Up @@ -497,7 +497,7 @@ public function testGetClassyElements81(array $expected, string $source): void

array_walk(
$expected,
static function (array &$element, $index) use ($tokens): void {
static function (array &$element, int $index) use ($tokens): void {
$element['token'] = $tokens[$index];
ksort($element);
}
Expand Down Expand Up @@ -683,7 +683,7 @@ public function testGetClassyElements82(array $expected, string $source): void

array_walk(
$expected,
static function (array &$element, $index) use ($tokens): void {
static function (array &$element, int $index) use ($tokens): void {
$element['token'] = $tokens[$index];
ksort($element);
},
Expand Down

0 comments on commit 48de1b2

Please sign in to comment.