This commit is contained in:
Tomas Votruba 2018-12-07 19:08:13 +01:00
parent 86ed54d316
commit a00ae17ab9
4 changed files with 19 additions and 10 deletions

View File

@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\Function_;
use Rector\NodeTypeResolver\Node\Attribute;
use Rector\RectorDefinition\CodeSample;
use Rector\RectorDefinition\RectorDefinition;
use Symplify\PackageBuilder\FileSystem\SmartFileInfo;
final class ParamScalarTypehintRector extends AbstractScalarTypehintRector
{
@ -136,7 +137,6 @@ CODE_SAMPLE
// inherit typehint to all children
if ($node instanceof ClassMethod) {
/** @var string $className */
$className = $node->getAttribute(Attribute::CLASS_NAME);
@ -154,12 +154,19 @@ CODE_SAMPLE
}
$childrenClassMethodParam = $childrenClassMethod->params[$i];
if ($childrenClassMethodParam->type === null) {
$childrenClassMethodParam->type = $paramTagInfo->getTypeNode();
// let the method know it was changed now
$childrenClassMethodParam->type->setAttribute(self::HAS_NEW_INHERITED_TYPE, true);
if ($childrenClassMethodParam->type !== null) {
continue;
}
$childrenClassMethodParam->type = $paramTagInfo->getTypeNode();
// let the method know it was changed now
$childrenClassMethodParam->type->setAttribute(self::HAS_NEW_INHERITED_TYPE, true);
// reprint the file
/** @var SmartFileInfo $fileInfo */
$fileInfo = $childrenClassMethod->getAttribute(Attribute::FILE_INFO);
$this->filesToReprintCollector->addFileInfo($fileInfo);
}
}
}

View File

@ -135,7 +135,7 @@ CODE_SAMPLE
/** @var SmartFileInfo $fileInfo */
$fileInfo = $childrenClassMethod->getAttribute(Attribute::FILE_INFO);
$this->filesToReprintCollector->addFileInfoWithNewTokens($fileInfo);
$this->filesToReprintCollector->addFileInfo($fileInfo);
}
}

View File

@ -10,9 +10,10 @@ class BoolClass
* @param true|false $ojoj3
* @param null|true|false $ojoj4
* @param int|null|true|false $ojoj5
* @param null|BOOL|true|false $ojoj6
* @return false
*/
function someFunction($ojoj, $ojoj2, $ojoj3, $ojoj4, $ojoj5)
function someFunction($ojoj, $ojoj2, $ojoj3, $ojoj4, $ojoj5, $ojoj6)
{
}
}
@ -31,9 +32,10 @@ class BoolClass
* @param true|false $ojoj3
* @param null|true|false $ojoj4
* @param int|null|true|false $ojoj5
* @param null|BOOL|true|false $ojoj6
* @return false
*/
function someFunction(bool $ojoj, bool $ojoj2, bool $ojoj3, ?bool $ojoj4, $ojoj5): bool
function someFunction(bool $ojoj, bool $ojoj2, bool $ojoj3, ?bool $ojoj4, $ojoj5, ?bool $ojoj6): bool
{
}
}

View File

@ -11,7 +11,7 @@ final class FilesToReprintCollector
*/
private $fileInfos = [];
public function addFileInfoWithNewTokens(SmartFileInfo $smartFileInfo): void
public function addFileInfo(SmartFileInfo $smartFileInfo): void
{
$this->fileInfos[$smartFileInfo->getRealPath()] = $smartFileInfo;
}