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

PSR2/ClassDeclaration: support namespace relative names / prevent fixer conflict #424

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ public function processOpen(File $phpcsFile, $stackPtr)
if ($checkingImplements === true
&& $multiLineImplements === true
&& ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR
|| $tokens[($className - 2)]['code'] !== T_STRING)
|| ($tokens[($className - 2)]['code'] !== T_STRING
&& $tokens[($className - 2)]['code'] !== T_NAMESPACE))
) {
$prev = $phpcsFile->findPrevious(
[
Expand Down Expand Up @@ -397,9 +398,10 @@ public function processOpen(File $phpcsFile, $stackPtr)
}
}//end if
} else if ($tokens[($className - 1)]['code'] !== T_NS_SEPARATOR
|| $tokens[($className - 2)]['code'] !== T_STRING
|| ($tokens[($className - 2)]['code'] !== T_STRING
&& $tokens[($className - 2)]['code'] !== T_NAMESPACE)
) {
// Not part of a longer fully qualified class name.
// Not part of a longer fully qualified or namespace relative class name.
if ($tokens[($className - 1)]['code'] === T_COMMA
|| ($tokens[($className - 1)]['code'] === T_NS_SEPARATOR
&& $tokens[($className - 2)]['code'] === T_COMMA)
Expand Down
11 changes: 11 additions & 0 deletions src/Standards/PSR2/Tests/Classes/ClassDeclarationUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,14 @@ readonly
class ReadonlyClassWithComment
{
}

// Safeguard against fixer conflict when there are namespace relative interface names in extends.
interface FooBar extends namespace\BarFoo
{
}

// Safeguard against fixer conflict when there are namespace relative interface names in a multi-line implements.
class BarFoo implements
namespace\BarFoo
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,14 @@ readonly
class ReadonlyClassWithComment
{
}

// Safeguard against fixer conflict when there are namespace relative interface names in extends.
interface FooBar extends namespace\BarFoo
{
}

// Safeguard against fixer conflict when there are namespace relative interface names in a multi-line implements.
class BarFoo implements
namespace\BarFoo
{
}