Skip to content

Commit 64c2c23

Browse files
authored
Merge pull request #555 from PHPCSStandards/feature/552-squiz-selfmemberreference-bugfix-close-tag
Squiz/SelfMemberReference: handle namespace declaration ending on PHP close tag
2 parents 2367a62 + 783371a commit 64c2c23

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/Standards/Squiz/Sniffs/Classes/SelfMemberReferenceSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ protected function getNamespaceOfScope(File $phpcsFile, $stackPtr)
225225
$namespaceDeclaration = $phpcsFile->findPrevious(T_NAMESPACE, $stackPtr);
226226

227227
if ($namespaceDeclaration !== false) {
228-
$endOfNamespaceDeclaration = $phpcsFile->findNext([T_SEMICOLON, T_OPEN_CURLY_BRACKET], $namespaceDeclaration);
228+
$endOfNamespaceDeclaration = $phpcsFile->findNext([T_SEMICOLON, T_OPEN_CURLY_BRACKET, T_CLOSE_TAG], $namespaceDeclaration);
229229
$namespace = $this->getDeclarationNameWithNamespace(
230230
$phpcsFile->getTokens(),
231231
($endOfNamespaceDeclaration - 1)

src/Standards/Squiz/Tests/Classes/SelfMemberReferenceUnitTest.inc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,14 @@ namespace Foo /*comment*/ \ Bah {
172172
}
173173
}
174174
}
175+
176+
namespace EndsIn\CloseTag ?>
177+
<?php
178+
179+
class Baz {
180+
function myFunction()
181+
{
182+
\EndsIn\CloseTag\Whatever::something();
183+
\EndsIn\CloseTag\Baz::something();
184+
}
185+
}

src/Standards/Squiz/Tests/Classes/SelfMemberReferenceUnitTest.inc.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,14 @@ namespace Foo /*comment*/ \ Bah {
160160
}
161161
}
162162
}
163+
164+
namespace EndsIn\CloseTag ?>
165+
<?php
166+
167+
class Baz {
168+
function myFunction()
169+
{
170+
\EndsIn\CloseTag\Whatever::something();
171+
self::something();
172+
}
173+
}

src/Standards/Squiz/Tests/Classes/SelfMemberReferenceUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function getErrorList()
4646
143 => 2,
4747
162 => 1,
4848
171 => 1,
49+
183 => 1,
4950
];
5051

5152
}//end getErrorList()

0 commit comments

Comments
 (0)