Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psr0Fixer - class with anonymous class #4217

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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