Skip to content

Commit

Permalink
MethodArgumentSpaceFixer - support for anonymous classses
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmajor committed Oct 27, 2021
1 parent 05ede95 commit fafb79b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function getPriority(): int
*/
protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
{
$expectedTokens = [T_LIST, T_FUNCTION, CT::T_USE_LAMBDA];
$expectedTokens = [T_LIST, T_FUNCTION, CT::T_USE_LAMBDA, T_CLASS];

if (\PHP_VERSION_ID >= 70400) {
$expectedTokens[] = T_FN;
Expand Down
27 changes: 27 additions & 0 deletions tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,19 @@ public function provideFixCases(): array
'<?php new Foo($a=10 , $b=20 , $c=30);',
['keep_multiple_spaces_after_comma' => true],
],
'test anonymous class constructor call' => [
'<?php new class ($a=10, $b=20, $this->foo(), $c=30) {};',
'<?php new class ($a=10,$b=20 ,$this->foo() ,$c=30) {};',
],
'test anonymous class constructor call with multiple spaces' => [
'<?php new class ($a=10, $b=20, $c=30) extends Foo {};',
'<?php new class ($a=10 , $b=20 , $c=30) extends Foo {};',
],
'test anonymous class constructor call with multiple spaces (kmsac)' => [
'<?php new class ($a=10, $b=20, $c=30) {};',
'<?php new class ($a=10 , $b=20 , $c=30) {};',
['keep_multiple_spaces_after_comma' => true],
],
'test receiving data in list context with omitted values' => [
'<?php list($a, $b, , , $c) = foo();',
'<?php list($a, $b,, ,$c) = foo();',
Expand Down Expand Up @@ -241,6 +254,20 @@ public function provideFixCases(): array
);
}',
],
'multi line anonymous class constructor call' => [
'<?php if (1) {
new class (
$a=10,
$b=20,
$c=30
) {};
}',
'<?php if (1) {
new class (
$a=10 ,
$b=20,$c=30) {};
}',
],
'skip arrays but replace arg methods' => [
'<?php fnc(1, array(2, func2(6, 7) ,4), 5);',
'<?php fnc(1,array(2, func2(6, 7) ,4), 5);',
Expand Down

0 comments on commit fafb79b

Please sign in to comment.