Skip to content

Commit

Permalink
minor: UseArrowFunctionsFixer - run before `FunctionDeclarationFixe…
Browse files Browse the repository at this point in the history
…r` (#7065)
  • Loading branch information
paulbalandan committed Jun 16, 2023
1 parent a7bbaa1 commit 376a987
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/FunctionDeclarationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function foo ($bar, $baz)
* {@inheritdoc}
*
* Must run before MethodArgumentSpaceFixer.
* Must run after SingleSpaceAfterConstructFixer, SingleSpaceAroundConstructFixer.
* Must run after SingleSpaceAfterConstructFixer, SingleSpaceAroundConstructFixer, UseArrowFunctionsFixer.
*/
public function getPriority(): int
{
Expand Down
10 changes: 10 additions & 0 deletions src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public function isRisky(): bool
return true;
}

/**
* {@inheritdoc}
*
* Must run before FunctionDeclarationFixer.
*/
public function getPriority(): int
{
return 32;
}

protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
$analyzer = new TokensAnalyzer($tokens);
Expand Down
3 changes: 3 additions & 0 deletions tests/AutoReview/FixerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,9 @@ private static function getFixersPriorityGraph(): array
'not_operator_with_space',
'not_operator_with_successor_space',
],
'use_arrow_functions' => [
'function_declaration',
],
'visibility_required' => [
'class_attributes_separation',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Integration of fixers: use_arrow_functions,function_declaration.
--RULESET--
{"use_arrow_functions": true, "function_declaration": {"closure_fn_spacing": "none"}}
--EXPECT--
<?php

$fn = static fn(string $class): bool => is_subclass_of($class, Exception::class);

--INPUT--
<?php

$fn = static function (string $class): bool {
return is_subclass_of($class, Exception::class);
};

0 comments on commit 376a987

Please sign in to comment.