Skip to content

Commit

Permalink
Psr0Fixer - class with anonymous class
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos committed Jan 2, 2019
1 parent 4537bfd commit e28c9e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Fixer/Basic/Psr0Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)

$namespace = trim($tokens->generatePartialCode($namespaceIndex, $namespaceEndIndex - 1));
} elseif ($token->isClassy()) {
if (null !== $classyName) {
return;
}

$prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
if ($prevToken->isGivenKind(T_NEW)) {
break;
}

if (null !== $classyName) {
return;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/Fixer/Basic/Psr0FixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,35 @@ class Psr0Fixer {}
$this->doTest($expected, null, $file);
}

/**
* @requires PHP 7.0
*/
public function testClassWithAnonymousClass()
{
$file = $this->getTestFile(__FILE__);

$expected = <<<'EOF'
<?php
namespace PhpCsFixer\Tests\Fixer\Basic;
class Psr0FixerTest {
public function foo() {
return new class() implements FooInterface {};
}
}
EOF;
$input = <<<'EOF'
<?php
namespace PhpCsFixer\Tests\Fixer\Basic;
class stdClass {
public function foo() {
return new class() implements FooInterface {};
}
}
EOF;

$this->doTest($expected, $input, $file);
}

/**
* @requires PHP 7.0
*/
Expand Down

0 comments on commit e28c9e4

Please sign in to comment.