Skip to content

Commit 10726ed

Browse files
Vrtak-CZondrejmirtes
authored andcommitted
Fixed ReferencedNameHelper to return underscored names from annotations (fixes #10)
1 parent 6ef9a07 commit 10726ed

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

SlevomatCodingStandard/Helpers/ReferencedNameHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static function createAllReferencedNames(PHP_CodeSniffer_File $phpcsFile
6565

6666
$matchTypesInAnnotation = function ($annotation, $nameStartPointer) use (&$types) {
6767
$annotation = trim($annotation, '@ ');
68-
if (preg_match('#([a-zA-Z0-9|\[\]\\\]+)#', $annotation, $matches) > 0) {
68+
if (preg_match('#([a-zA-Z0-9_|\[\]\\\]+)#', $annotation, $matches) > 0) {
6969
$referencedNames = array_filter(array_map(function ($name) {
7070
return trim($name, '[]');
7171
}, explode('|', $matches[1])), function ($match) {

tests/Helpers/ReferencedNameHelperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function dataGetAllReferencedNames()
3737
'\Foo\BarBaz',
3838
'TypehintedName',
3939
'AnotherTypehintedName',
40+
'Returned_Typehinted_Underscored_Name',
4041
'ClassInstance',
4142
'StaticClass',
4243
'\Foo\Bar\SpecificException',

tests/Helpers/data/lotsOfReferencedNames.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class FooClass extends \ExtendedClass implements \ImplementedInterface
2626
/**
2727
* @param TypehintedName $foo
2828
* @param AnotherTypehintedName[] $bar
29+
* @return Returned_Typehinted_Underscored_Name
2930
*/
3031
public function fooMethod(TypehintedName $foo, array $bar)
3132
{

tests/Sniffs/Namespaces/UnusedUsesSniffTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,12 @@ public function testUsedTrait()
7878
$this->assertNoSniffError($report, 5);
7979
}
8080

81+
public function testTypeWithUnderscoresInAnnotation()
82+
{
83+
$report = $this->checkFile(__DIR__ . '/data/unusedUsesAnnotationUnderscores.php', [
84+
'searchAnnotations' => true,
85+
]);
86+
$this->assertNoSniffError($report, 5);
87+
}
88+
8189
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Foo;
4+
5+
use Test_Invalid;
6+
7+
abstract class TestInvalidClass
8+
{
9+
10+
/**
11+
* @return Test_Invalid
12+
*/
13+
protected function getCell()
14+
{
15+
return NULL;
16+
}
17+
18+
}

0 commit comments

Comments
 (0)