Skip to content

Commit

Permalink
[StandaloneLineConstructorParamFixer] Ignore constructor without argu…
Browse files Browse the repository at this point in the history
…ments (#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
  • Loading branch information
ruudk authored Oct 31, 2023
1 parent bf8f561 commit aceaedf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ public function findInTokensByEdge(Tokens $tokens, int $position): ?BlockInfo
if ($token->equals(';')) {
return null;
}

if ($position !== null && $token->equals('(')) {
$closingPosition = $tokens->getNextMeaningfulToken($position);
if ($closingPosition !== null) {
$closingToken = $tokens[$closingPosition];
if ($closingToken->equals(')')) {
// function has no arguments
return null;
}
}
}
}

// some invalid code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Symplify\CodingStandard\Tests\Fixer\Spacing\StandaloneLineConstructorParamFixer\Fixture;

final class EmptyConstructor
{
public function __construct()
{
echo "Hello, World!";
}
}

?>

0 comments on commit aceaedf

Please sign in to comment.