Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuperfluousPhpdocTagsFixer - handle null in every position #3884

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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