Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

class OverrideDummyArrayParam
{
public function go()
{
$this->run(['item1', 'item2']);
}

/**
* @param array $items
*/
private function run(array $items)
{
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Fixture;

class OverrideDummyArrayParam
{
public function go()
{
$this->run(['item1', 'item2']);
}

/**
* @param string[] $items
*/
private function run(array $items)
{
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Rector\Rector\AbstractRector;
use Rector\TypeDeclaration\NodeAnalyzer\CallTypesResolver;
use Rector\TypeDeclarationDocblocks\NodeDocblockTypeDecorator;
use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -29,6 +30,7 @@ public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly CallTypesResolver $callTypesResolver,
private readonly LocalMethodCallFinder $localMethodCallFinder,
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer,
private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator
) {
}
Expand Down Expand Up @@ -103,7 +105,7 @@ public function refactor(Node $node): ?Node
$parameterTagValueNode = $classMethodPhpDocInfo->getParamTagValueByName($parameterName);

// already known, skip
if ($parameterTagValueNode instanceof ParamTagValueNode) {
if ($this->usefulArrayTagNodeAnalyzer->isUsefulArrayTag($parameterTagValueNode)) {
continue;
}

Expand All @@ -112,14 +114,6 @@ public function refactor(Node $node): ?Node
continue;
}

if ($resolvedParameterType instanceof MixedType) {
continue;
}

if ($resolvedParameterType instanceof ArrayType && $resolvedParameterType->getItemType() instanceof MixedType && $resolvedParameterType->getKeyType() instanceof MixedType) {
continue;
}

// in case of array type declaration, null cannot be passed or is already casted
$resolvedParameterType = TypeCombinator::removeNull($resolvedParameterType);

Expand Down