Skip to content

Commit

Permalink
bug #3951 NoSuperfluousPhpdocTagsFixer - do not call strtolower with …
Browse files Browse the repository at this point in the history
…null (SpacePossum)

This PR was merged into the 2.12 branch.

Discussion
----------

NoSuperfluousPhpdocTagsFixer - do not call strtolower with null

for ref.: https://travis-ci.org/FriendsOfPHP/PHP-CS-Fixer/jobs/409620287#L946

Commits
-------

7f25fc8 NoSuperfluousPhpdocTagsFixer - do not call strtolower with null
  • Loading branch information
SpacePossum committed Jul 30, 2018
2 parents a79401b + 7f25fc8 commit 308e5a6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 37 deletions.
20 changes: 17 additions & 3 deletions src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php
Expand Up @@ -147,6 +147,13 @@ private function findDocumentedFunction(Tokens $tokens, $index)
return null;
}

/**
* @param Tokens $tokens
* @param int $start
* @param int $end
*
* @return array<string, array>
*/
private function getArgumentsInfo(Tokens $tokens, $start, $end)
{
$argumentsInfo = [];
Expand Down Expand Up @@ -226,6 +233,13 @@ private function parseTypeHint(Tokens $tokens, $index)
];
}

/**
* @param Annotation $annotation
* @param array $info
* @param array<string, string> $symbolShortNames
*
* @return bool
*/
private function annotationIsSuperfluous(Annotation $annotation, array $info, array $symbolShortNames)
{
if ('param' === $annotation->getTag()->getName()) {
Expand All @@ -244,7 +258,7 @@ private function annotationIsSuperfluous(Annotation $annotation, array $info, ar
return true;
}

$actualTypes = [$info['type']];
$actualTypes = null === $info['type'] ? [] : [$info['type']];
if ($info['allows_null']) {
$actualTypes[] = 'null';
}
Expand All @@ -258,8 +272,8 @@ private function annotationIsSuperfluous(Annotation $annotation, array $info, ar
* 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
* @param string[] $types The types to normalize
* @param array<string, string> $symbolShortNames The imports aliases
*
* @return array The normalized types
*/
Expand Down
68 changes: 34 additions & 34 deletions tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php
Expand Up @@ -35,7 +35,7 @@ public function testFix($expected, $input = null)
public function provideFixCases()
{
return [
'no_typehint' => [
'no typehint' => [
'<?php
class Foo {
/**
Expand All @@ -46,7 +46,7 @@ class Foo {
public function doFoo($bar) {}
}',
],
'same_typehint' => [
'same typehint' => [
'<?php
class Foo {
/**
Expand All @@ -61,7 +61,7 @@ class Foo {
public function doFoo(Bar $bar) {}
}',
],
'same_optional_typehint' => [
'same optional typehint' => [
'<?php
class Foo {
/**
Expand All @@ -76,7 +76,7 @@ class Foo {
public function doFoo(Bar $bar = null) {}
}',
],
'same_typehint_with_description' => [
'same typehint with description' => [
'<?php
class Foo {
/**
Expand All @@ -85,7 +85,7 @@ class Foo {
public function doFoo(Bar $bar) {}
}',
],
'no_typehint_mixed' => [
'no typehint mixed' => [
'<?php
class Foo {
/**
Expand All @@ -103,7 +103,7 @@ class Foo {
public function doFoo($bar) {}
}',
],
'multiple_different_types' => [
'multiple different types' => [
'<?php
class Foo {
/**
Expand All @@ -112,7 +112,7 @@ class Foo {
public function doFoo(Bar $bar) {}
}',
],
'same_typehint_with_different_casing' => [
'same typehint with different casing' => [
'<?php
class Foo {
/**
Expand All @@ -127,7 +127,7 @@ class Foo {
public function doFoo(Bar $bar) {}
}',
],
'multiple_arguments' => [
'multiple arguments' => [
'<?php
class Foo {
/**
Expand All @@ -144,7 +144,7 @@ class Foo {
public function doFoo(Bar $bar, Baz $baz = null) {}
}',
],
'with_import' => [
'with import' => [
'<?php
use Foo\Bar;
Expand All @@ -159,7 +159,7 @@ function foo(Bar $bar) {}',
*/
function foo(Bar $bar) {}',
],
'with_root_symbols' => [
'with root symbols' => [
'<?php
/**
*/
Expand All @@ -170,7 +170,7 @@ function foo(\Foo\Bar $bar) {}',
*/
function foo(\Foo\Bar $bar) {}',
],
'with_mix_of_imported_and_fully_qualified_symbols' => [
'with mix of imported and fully qualified symbols' => [
'<?php
use Foo\Bar;
use Foo\Baz;
Expand All @@ -188,7 +188,7 @@ function foo(Bar $bar, \Foo\Baz $baz) {}',
*/
function foo(Bar $bar, \Foo\Baz $baz) {}',
],
'with_aliased_imported' => [
'with aliased imported' => [
'<?php
use Foo\Bar as Baz;
Expand All @@ -203,7 +203,7 @@ function foo(Baz $bar) {}',
*/
function foo(Baz $bar) {}',
],
'with_unmapped_param' => [
'with unmapped param' => [
'<?php
use Foo\Bar;
Expand All @@ -212,7 +212,7 @@ function foo(Baz $bar) {}',
*/
function foo(Bar $bar) {}',
],
'with_param_superfluous_but_not_return' => [
'with param superfluous but not return' => [
'<?php
class Foo {
/**
Expand All @@ -231,7 +231,7 @@ class Foo {
public function doFoo(Bar $bar) {}
}',
],
'with_not_all_params_superfluous' => [
'with not all params superfluous' => [
'<?php
class Foo {
/**
Expand All @@ -248,7 +248,7 @@ class Foo {
public function doFoo(Bar $bar, $baxz) {}
}',
],
'with_special_type_hints' => [
'with special type hints' => [
'<?php
class Foo {
/**
Expand Down Expand Up @@ -282,7 +282,7 @@ public function testFixPhp70($expected, $input = null)
public function provideFixPhp70Cases()
{
return [
'same_typehint' => [
'same type hint' => [
'<?php
class Foo {
/**
Expand All @@ -300,7 +300,7 @@ class Foo {
public function doFoo(Bar $bar): Baz {}
}',
],
'same_typehint_with_description' => [
'same type hint with description' => [
'<?php
class Foo {
/**
Expand All @@ -311,7 +311,7 @@ class Foo {
public function doFoo(Bar $bar): Baz {}
}',
],
'multiple_different_types' => [
'multiple different types' => [
'<?php
class Foo {
/**
Expand All @@ -322,7 +322,7 @@ class Foo {
public function doFoo(Bar $bar): Baz {}
}',
],
'with_import' => [
'with import' => [
'<?php
use Foo\Bar;
use Foo\Baz;
Expand All @@ -340,7 +340,7 @@ function foo(Bar $bar): Baz {}',
*/
function foo(Bar $bar): Baz {}',
],
'with_root_symbols' => [
'with root symbols' => [
'<?php
/**
*/
Expand All @@ -352,7 +352,7 @@ function foo(\Foo\Bar $bar): \Foo\Baz {}',
*/
function foo(\Foo\Bar $bar): \Foo\Baz {}',
],
'with_mix_of_imported_and_fully_qualified_symbols' => [
'with mix of imported and fully qualified symbols' => [
'<?php
use Foo\Bar;
use Foo\Baz;
Expand All @@ -373,7 +373,7 @@ function foo(Bar $bar, \Foo\Baz $baz): \Foo\Qux {}',
*/
function foo(Bar $bar, \Foo\Baz $baz): \Foo\Qux {}',
],
'with_aliased_imported' => [
'with aliased imported' => [
'<?php
use Foo\Bar as Baz;
Expand All @@ -389,7 +389,7 @@ function foo(Baz $bar): Baz {}',
*/
function foo(Baz $bar): Baz {}',
],
'with_scalar_type_hints' => [
'with scalar type hints' => [
'<?php
class Foo {
/**
Expand Down Expand Up @@ -426,7 +426,7 @@ public function testFixPhp71($expected, $input = null)
public function provideFixPhp71Cases()
{
return [
'same_nullable_typehint' => [
'same nullable type hint' => [
'<?php
class Foo {
/**
Expand All @@ -444,7 +444,7 @@ class Foo {
public function doFoo(?Bar $bar): ?Baz {}
}',
],
'same_nullable_typehint_reversed' => [
'same nullable type hint reversed' => [
'<?php
class Foo {
/**
Expand All @@ -462,7 +462,7 @@ class Foo {
public function doFoo(?Bar $bar): ?Baz {}
}',
],
'same_nullable_typehint_with_description' => [
'same nullable type hint with description' => [
'<?php
class Foo {
/**
Expand All @@ -473,7 +473,7 @@ class Foo {
public function doFoo(?Bar $bar): ?Baz {}
}',
],
'same_optional_nullable_typehint' => [
'same optional nullable type hint' => [
'<?php
class Foo {
/**
Expand All @@ -488,7 +488,7 @@ class Foo {
public function doFoo(?Bar $bar = null) {}
}',
],
'multiple_different_types' => [
'multiple different types' => [
'<?php
class Foo {
/**
Expand All @@ -499,7 +499,7 @@ class Foo {
public function doFoo(?Bar $bar): ?Baz {}
}',
],
'with_import' => [
'with import' => [
'<?php
use Foo\Bar;
use Foo\Baz;
Expand All @@ -517,7 +517,7 @@ function foo(?Bar $bar): ?Baz {}',
*/
function foo(?Bar $bar): ?Baz {}',
],
'with_root_symbols' => [
'with root symbols' => [
'<?php
/**
*/
Expand All @@ -529,7 +529,7 @@ function foo(?\Foo\Bar $bar): ?\Foo\Baz {}',
*/
function foo(?\Foo\Bar $bar): ?\Foo\Baz {}',
],
'with_mix_of_imported_and_fully_qualified_symbols' => [
'with mix of imported and fully qualified symbols' => [
'<?php
use Foo\Bar;
use Foo\Baz;
Expand All @@ -550,7 +550,7 @@ function foo(?Bar $bar, ?\Foo\Baz $baz): ?\Foo\Qux {}',
*/
function foo(?Bar $bar, ?\Foo\Baz $baz): ?\Foo\Qux {}',
],
'with_aliased_imported' => [
'with aliased imported' => [
'<?php
use Foo\Bar as Baz;
Expand All @@ -566,7 +566,7 @@ function foo(?Baz $bar): ?Baz {}',
*/
function foo(?Baz $bar): ?Baz {}',
],
'with_special_type_hints' => [
'with special type hints' => [
'<?php
class Foo {
/**
Expand Down

0 comments on commit 308e5a6

Please sign in to comment.