Skip to content

Commit

Permalink
Fixed ReferencedNameHelper to return underscored names from annotatio…
Browse files Browse the repository at this point in the history
…ns (fixes #10)
  • Loading branch information
Vrtak-CZ authored and ondrejmirtes committed Dec 30, 2015
1 parent 6ef9a07 commit 10726ed
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SlevomatCodingStandard/Helpers/ReferencedNameHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static function createAllReferencedNames(PHP_CodeSniffer_File $phpcsFile

$matchTypesInAnnotation = function ($annotation, $nameStartPointer) use (&$types) {
$annotation = trim($annotation, '@ ');
if (preg_match('#([a-zA-Z0-9|\[\]\\\]+)#', $annotation, $matches) > 0) {
if (preg_match('#([a-zA-Z0-9_|\[\]\\\]+)#', $annotation, $matches) > 0) {
$referencedNames = array_filter(array_map(function ($name) {
return trim($name, '[]');
}, explode('|', $matches[1])), function ($match) {
Expand Down
1 change: 1 addition & 0 deletions tests/Helpers/ReferencedNameHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function dataGetAllReferencedNames()
'\Foo\BarBaz',
'TypehintedName',
'AnotherTypehintedName',
'Returned_Typehinted_Underscored_Name',
'ClassInstance',
'StaticClass',
'\Foo\Bar\SpecificException',
Expand Down
1 change: 1 addition & 0 deletions tests/Helpers/data/lotsOfReferencedNames.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FooClass extends \ExtendedClass implements \ImplementedInterface
/**
* @param TypehintedName $foo
* @param AnotherTypehintedName[] $bar
* @return Returned_Typehinted_Underscored_Name
*/
public function fooMethod(TypehintedName $foo, array $bar)
{
Expand Down
8 changes: 8 additions & 0 deletions tests/Sniffs/Namespaces/UnusedUsesSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,12 @@ public function testUsedTrait()
$this->assertNoSniffError($report, 5);
}

public function testTypeWithUnderscoresInAnnotation()
{
$report = $this->checkFile(__DIR__ . '/data/unusedUsesAnnotationUnderscores.php', [
'searchAnnotations' => true,
]);
$this->assertNoSniffError($report, 5);
}

}
18 changes: 18 additions & 0 deletions tests/Sniffs/Namespaces/data/unusedUsesAnnotationUnderscores.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Foo;

use Test_Invalid;

abstract class TestInvalidClass
{

/**
* @return Test_Invalid
*/
protected function getCell()
{
return NULL;
}

}

0 comments on commit 10726ed

Please sign in to comment.