Skip to content

Commit 3d76bbb

Browse files
committed
Fixed bug #19871 : findExtendedClassName doesn't return FQCN on namespaced classes
1 parent 638d340 commit 3d76bbb

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CodeSniffer/File.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2848,12 +2848,21 @@ public function findExtendedClassName($stackPtr)
28482848
return false;
28492849
}
28502850

2851-
$stringIndex = $this->findNext(T_STRING, $extendsIndex, $classCloserIndex);
2852-
if (false === $stringIndex) {
2851+
$find = array(
2852+
T_NS_SEPARATOR,
2853+
T_STRING,
2854+
T_WHITESPACE,
2855+
);
2856+
2857+
$end = $this->findNext($find, ($extendsIndex + 1), $classCloserIndex, true);
2858+
$name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2859+
$name = trim($name);
2860+
2861+
if ($name === '') {
28532862
return false;
28542863
}
28552864

2856-
return $this->_tokens[$stringIndex]['content'];
2865+
return $name;
28572866

28582867
}//end findExtendedClassName()
28592868

CodeSniffer/Standards/Generic/Tests/NamingConventions/ConstructorNameUnitTest.inc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ class MyClass
2828
}
2929

3030
}
31-
?>
31+
32+
class MyClass extends \MyNamespace\SomeClass
33+
{
34+
function __construct() {
35+
something::MyNamespace();
36+
}
37+
38+
}
39+
?>

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5353
- Fixed bug #19819 : Freeze with syntax error in use statement
5454
- Fixed bug #19820 : Wrong message level in Generic_Sniffs_CodeAnalysis_EmptyStatementSniff
5555
- Fixed bug #19859 : CodeSniffer::setIgnorePatterns API changed
56+
- Fixed bug #19871 : findExtendedClassName doesn't return FQCN on namespaced classes
5657
</notes>
5758
<contents>
5859
<dir name="/">

0 commit comments

Comments
 (0)