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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class ObjectsOverruleEmptyArray
$this->run($emptyArray);
}

public function run(array $result)
private function run(array $result)
{
}

Expand Down Expand Up @@ -56,7 +56,7 @@ final class ObjectsOverruleEmptyArray
/**
* @param \Rector\Tests\TypeDeclarationDocblocks\Rector\Class_\ClassMethodArrayDocblockParamFromLocalCallsRector\Source\SomeReturnedObject[] $result
*/
public function run(array $result)
private function run(array $result)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

final class SkipProtected
{
public function go()
{
$this->run([2512, 3423]);

$this->run([324, 534]);
}

protected function run(array $items)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

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

final class SkipPublic
{
public function go()
{
$this->run([2512, 3423]);

$this->run([324, 534]);
}

public function run(array $items)
{
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\NodeManipulator\ClassMethodManipulator;
use Rector\PhpParser\NodeFinder\LocalMethodCallFinder;
use Rector\Rector\AbstractRector;
use Rector\TypeDeclaration\NodeAnalyzer\CallTypesResolver;
Expand All @@ -31,8 +29,7 @@ public function __construct(
private readonly CallTypesResolver $callTypesResolver,
private readonly LocalMethodCallFinder $localMethodCallFinder,
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer,
private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator,
private readonly ClassMethodManipulator $classMethodManipulator
private readonly NodeDocblockTypeDecorator $nodeDocblockTypeDecorator
) {
}

Expand Down Expand Up @@ -92,8 +89,8 @@ public function refactor(Node $node): ?Node
continue;
}

// parent/interface method may declare a wider @param contract; local calls are narrower, so skip to keep LSP
if ($this->classMethodManipulator->hasParentMethodOrInterfaceMethod($node, $this->getName($classMethod))) {
// only private methods have a closed set of local callers; public/protected can be called from outside
if (! $classMethod->isPrivate()) {
continue;
}

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

if ($parameterTagValueNode instanceof ParamTagValueNode
&& $classMethod->isPublic() &&
$this->usefulArrayTagNodeAnalyzer->isMixedArray($parameterTagValueNode->type)) {
// on public method, skip if there is mixed[], as caller can be anything
continue;
}

$resolvedParameterType = $classMethodParameterTypes[$parameterPosition] ?? $classMethodParameterTypes[$parameterName] ?? null;

if (! $resolvedParameterType instanceof Type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function isUsefulArrayTag(null|ReturnTagValueNode|ParamTagValueNode|VarTa
return ! in_array($type->name, ['array', 'mixed', 'iterable'], true);
}

public function isMixedArray(TypeNode $typeNode): bool
private function isMixedArray(TypeNode $typeNode): bool
{
return $typeNode instanceof SpacingAwareArrayTypeNode && $typeNode->type instanceof IdentifierTypeNode && $typeNode->type->name === 'mixed';
}
Expand Down
Loading