Skip to content

Commit

Permalink
PhpdocToParamTypeFixer - fix for void as param
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and keradus committed Jun 27, 2020
1 parent a4e94a9 commit a373054
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ final class PhpdocToParamTypeFixer extends AbstractFixer implements Configuratio
'mixed' => true,
'resource' => true,
'static' => true,
'void' => true,
];

/**
Expand Down Expand Up @@ -157,7 +158,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)

$hasIterable = false;
$hasNull = false;
$hasVoid = false;
$hasArray = false;
$hasString = false;
$hasInt = false;
Expand Down Expand Up @@ -189,11 +189,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$minimumTokenPhpVersion = 70100;
}

if ('void' === $type) {
$hasVoid = true;
unset($types[$key]);
}

if ('string' === $type) {
$hasString = true;
unset($types[$key]);
Expand Down Expand Up @@ -270,7 +265,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
$hasNull,
$hasArray,
$hasIterable,
$hasVoid,
$hasString,
$hasInt,
$hasFloat,
Expand Down Expand Up @@ -358,7 +352,6 @@ private function hasParamTypeHint(Tokens $tokens, $index)
* @param bool $hasNull
* @param bool $hasArray
* @param bool $hasIterable
* @param bool $hasVoid
* @param bool $hasString
* @param bool $hasInt
* @param bool $hasFloat
Expand All @@ -373,7 +366,6 @@ private function fixFunctionDefinition(
$hasNull,
$hasArray,
$hasIterable,
$hasVoid,
$hasString,
$hasInt,
$hasFloat,
Expand All @@ -383,9 +375,7 @@ private function fixFunctionDefinition(
) {
$newTokens = [];

if (true === $hasVoid) {
$newTokens[] = new Token('void');
} elseif (true === $hasIterable && true === $hasArray) {
if (true === $hasIterable && true === $hasArray) {
$newTokens[] = new Token([CT::T_ARRAY_TYPEHINT, 'array']);
} elseif (true === $hasIterable) {
$newTokens[] = new Token([T_STRING, 'iterable']);
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ class Foo {
'<?php /** @param null|string[] $matches */ function matchAll(&$matches) {}',
70100,
],
'void as type in phpdoc' => [
'<?php /** @param void $bar */ function foo($bar) {}',
],
];
}
}

0 comments on commit a373054

Please sign in to comment.