Skip to content

Commit

Permalink
Merge 342ca69 into 5dc0c58
Browse files Browse the repository at this point in the history
  • Loading branch information
pepakriz committed Jan 9, 2017
2 parents 5dc0c58 + 342ca69 commit 81196c2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions SlevomatCodingStandard/Helpers/ReferencedNameHelper.php
Expand Up @@ -83,6 +83,7 @@ private static function createAllReferencedNames(\PHP_CodeSniffer_File $phpcsFil
T_USE, // trait
T_NEW,
T_COLON, // return type hint
T_NULLABLE, // nullable type hint
], true)
&& !in_array($tokens[$nextTokenAfterEndPointer]['code'], [
T_DOUBLE_COLON,
Expand Down
20 changes: 20 additions & 0 deletions tests/Helpers/ReferencedNameHelperTest.php
Expand Up @@ -44,6 +44,26 @@ public function testGetAllReferencedNames()
}
}

public function testGetAllReferencedNamesWithNullableTypehints()
{
$codeSnifferFile = $this->getCodeSnifferFile(
__DIR__ . '/data/referencedNamesWithNullableTypeHints.php'
);

$foundTypes = [
['NullableParameterTypeHint', false, false],
['NullableReturnTypeHint', false, false],
];

$names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0);
$this->assertCount(count($foundTypes), $names);
foreach ($names as $i => $referencedName) {
$this->assertSame($foundTypes[$i][0], $referencedName->getNameAsReferencedInFile());
$this->assertSame($foundTypes[$i][1], $referencedName->isFunction(), $foundTypes[$i][0]);
$this->assertSame($foundTypes[$i][2], $referencedName->isConstant(), $foundTypes[$i][0]);
}
}

public function testMultipleExceptionsCatch()
{
$codeSnifferFile = $this->getCodeSnifferFile(
Expand Down
13 changes: 13 additions & 0 deletions tests/Helpers/data/referencedNamesWithNullableTypeHints.php
@@ -0,0 +1,13 @@
<?php // lint >= 7.1

namespace FooNamespace;

class FooClass
{

public function nullableReturnTypeHint(?NullableParameterTypeHint $data): ?NullableReturnTypeHint
{

}

}

0 comments on commit 81196c2

Please sign in to comment.