Skip to content

Commit 5dd2e39

Browse files
committed
Psr4Fixer - fix for multiple classy elements in file
1 parent 7e0a86a commit 5dd2e39

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/Fixer/Basic/Psr4Fixer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
6666
} elseif ($token->isClassy()) {
6767
$prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
6868
if ($prevToken->isGivenKind(T_NEW)) {
69+
break;
70+
}
71+
72+
if (null !== $classyName) {
6973
return;
7074
}
7175

7276
$classyIndex = $tokens->getNextMeaningfulToken($index);
7377
$classyName = $tokens[$classyIndex]->getContent();
74-
75-
break;
7678
}
7779
}
7880

tests/Fixer/Basic/Psr0FixerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ class Psr0_fOo_bAr {}
5757
$this->doTest($expected, $input, $file);
5858
}
5959

60-
public function testFixIgnoreMultipleClassyInFile()
60+
public function testIgnoreMultipleClassyInFile()
6161
{
62-
$file = $this->getTestFile(__FILE__);
62+
$file = $this->getTestFile(__FILE__);
6363

64-
$expected = <<<'EOF'
64+
$expected = <<<'EOF'
6565
<?php
6666
namespace PhpCsFixer\Tests\Fixer\Basic;
6767
interface SomeInterfaceToBeUsedInTests {}
6868
class blah {}
6969
/* class foo */
7070
EOF;
7171

72-
$this->doTest($expected, null, $file);
72+
$this->doTest($expected, null, $file);
7373
}
7474

7575
public function testFixClassName()

tests/Fixer/Basic/Psr4FixerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ class Psr4_fOo_bAr {}
5757
$this->doTest($expected, $input, $file);
5858
}
5959

60-
public function testFixIgnoreMultipleClassyInFile()
60+
public function testIgnoreMultipleClassyInFile()
6161
{
62-
$file = $this->getTestFile(__FILE__);
62+
$file = $this->getTestFile(__FILE__);
6363

64-
$expected = <<<'EOF'
64+
$expected = <<<'EOF'
6565
<?php
6666
namespace PhpCsFixer\Tests\Fixer\Basic;
6767
interface SomeInterfaceToBeUsedInTests {}
6868
class blah {}
6969
/* class foo */
7070
EOF;
7171

72-
$this->doTest($expected, null, $file);
72+
$this->doTest($expected, null, $file);
7373
}
7474

7575
public function testFixClassName()

0 commit comments

Comments
 (0)