Skip to content

Commit aceaedf

Browse files
authored
[StandaloneLineConstructorParamFixer] Ignore constructor without arguments (#32)
* Add failing test for StandaloneLineConstructorParamFixer When you have a constructor without arguments, the fixer changes it to: ```diff -protected function __construct() { +protected function __construct( +) { ``` Not sure how to solve this. * Ignore when function has no arguments
1 parent bf8f561 commit aceaedf

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public function findInTokensByEdge(Tokens $tokens, int $position): ?BlockInfo
6161
if ($token->equals(';')) {
6262
return null;
6363
}
64+
65+
if ($position !== null && $token->equals('(')) {
66+
$closingPosition = $tokens->getNextMeaningfulToken($position);
67+
if ($closingPosition !== null) {
68+
$closingToken = $tokens[$closingPosition];
69+
if ($closingToken->equals(')')) {
70+
// function has no arguments
71+
return null;
72+
}
73+
}
74+
}
6475
}
6576

6677
// some invalid code
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Symplify\CodingStandard\Tests\Fixer\Spacing\StandaloneLineConstructorParamFixer\Fixture;
4+
5+
final class EmptyConstructor
6+
{
7+
public function __construct()
8+
{
9+
echo "Hello, World!";
10+
}
11+
}
12+
13+
?>

0 commit comments

Comments
 (0)