Skip to content

Commit

Permalink
bug #3884 NoSuperfluousPhpdocTagsFixer - handle null in every positio…
Browse files Browse the repository at this point in the history
…n (dmvdbrugge, julienfalque)

This PR was squashed before being merged into the 2.12 branch (closes #3884).

Discussion
----------

NoSuperfluousPhpdocTagsFixer - handle null in every position

… instead of last only.

This fixes #3849

Commits
-------

9956636 NoSuperfluousPhpdocTagsFixer - handle null in every position
  • Loading branch information
SpacePossum committed Jul 9, 2018
2 parents dcc87d5 + 9956636 commit fe9406f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Expand Up @@ -255,8 +255,8 @@ private function annotationIsSuperfluous(Annotation $annotation, array $info, ar
/**
* Normalizes types to make them comparable.
*
* Converts given types to lowercase and replaces imports aliases with
* their matching FQCN.
* Converts given types to lowercase, replaces imports aliases with
* their matching FQCN, and finally sorts the result.
*
* @param array $types The types to normalize
* @param array $symbolShortNames The imports aliases
Expand All @@ -265,7 +265,7 @@ private function annotationIsSuperfluous(Annotation $annotation, array $info, ar
*/
private function toComparableNames(array $types, array $symbolShortNames)
{
return array_map(
$normalized = array_map(
function ($type) use ($symbolShortNames) {
$type = strtolower($type);

Expand All @@ -277,5 +277,9 @@ function ($type) use ($symbolShortNames) {
},
$types
);

sort($normalized);

return $normalized;
}
}
18 changes: 18 additions & 0 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Expand Up @@ -442,6 +442,24 @@ class Foo {
* @return Baz|null
*/
public function doFoo(?Bar $bar): ?Baz {}
}',
],
'same_nullable_typehint_reversed' => [
'<?php
class Foo {
/**
*
*/
public function doFoo(?Bar $bar): ?Baz {}
}',
'<?php
class Foo {
/**
* @param null|Bar $bar
*
* @return null|Baz
*/
public function doFoo(?Bar $bar): ?Baz {}
}',
],
'same_nullable_typehint_with_description' => [
Expand Down

0 comments on commit fe9406f

Please sign in to comment.