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,12 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDimFetchAccessRector\Fixture;

use Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDimFetchAccessRector\Source\EnforcingSomeContractInterface;

final class SkipContractEnforced implements EnforcingSomeContractInterface
{
public function process(array $data): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDimFetchAccessRector\Source;

interface EnforcingSomeContractInterface
{
/**
* @param mixed $data
*/
public function process(array $data): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function isPromotedProperty(Class_ $class, string $propertyName): bool
continue;
}

$paramName = $this->getName($param->var);
$paramName = $this->getName($param);
if ($paramName === $propertyName) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ private function resolveParamByRefVariables(ClassMethod|Function_|Closure $node)
continue;
}

$paramName = $this->getName($param->var);
if ($paramName === null) {
continue;
}

$paramByRefVariables[] = $paramName;
$paramByRefVariables[] = $this->getName($param);
}

return $paramByRefVariables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function refactor(Node $node): ?Node
continue;
}

$variableNames[] = (string) $this->getName($param->var);
$variableNames[] = $this->getName($param);
}

if ($variableNames === []) {
Expand Down
4 changes: 1 addition & 3 deletions rules/Naming/Naming/ExpectedNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public function resolveForParamIfNotYet(Param $param): ?string
return null;
}

/** @var string $currentName */
$currentName = $this->nodeNameResolver->getName($param->var);

$currentName = $this->nodeNameResolver->getName($param);
if ($currentName === $expectedName || str_ends_with($currentName, ucfirst($expectedName))) {
return null;
}
Expand Down
6 changes: 1 addition & 5 deletions rules/Naming/ValueObjectFactory/ParamRenameFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public function createFromResolvedExpectedName(
return null;
}

$currentName = $this->nodeNameResolver->getName($param->var);
if ($currentName === null) {
return null;
}

$currentName = $this->nodeNameResolver->getName($param);
return new ParamRename($currentName, $expectedName, $param->var, $functionLike);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,8 @@ public function refactor(Node $node): ?Node
$assignStmtPosition = $promotionCandidate->getStmtPosition();
unset($constructClassMethod->stmts[$assignStmtPosition]);

/** @var string $oldName */
$oldName = $this->getName($param->var);
$this->variableRenamer->renameVariableInFunctionLike($constructClassMethod, $oldName, $propertyName, null);
$oldParamName = $this->getName($param);
$this->variableRenamer->renameVariableInFunctionLike($constructClassMethod, $oldParamName, $propertyName);

$paramTagValueNode = $constructorPhpDocInfo->getParamTagValueByName($paramName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function refactor(Node $node): ?Node
($functionLike instanceof Closure || $functionLike instanceof ArrowFunction) &&
(
$this->breakingVariableRenameGuard->shouldSkipVariable(
(string) $this->getName($param->var),
$this->getName($param),
$renameFunctionLikeParamWithinCallLikeArg->getNewParamName(),
$functionLike,
$param->var
Expand Down
5 changes: 1 addition & 4 deletions rules/TypeDeclaration/Guard/ParamTypeAddGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public function __construct(

public function isLegal(Param $param, ClassMethod $classMethod): bool
{
$paramName = $this->nodeNameResolver->getName($param->var);
if ($paramName === null) {
return false;
}
$paramName = $this->nodeNameResolver->getName($param);

$isLegal = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public function refactor(Node $node): ?Node
continue;
}

/** @var string $paramName */
$paramName = $this->getName($param->var);
$paramName = $this->getName($param);

$dimFetches = $this->arrayDimFetchFinder->findByDimName($classMethod, $paramName);
if ($dimFetches === []) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public function refactor(Node $node): ClassMethod|Function_|Closure|ArrowFunctio
continue;
}

/** @var string $variableName */
$variableName = $this->getName($param->var);
$variableName = $this->getName($param);

if (! $this->variableInSprintfMaskMatcher->matchMask($node, $variableName, '%s')) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ public function refactor(Node $node): ?Node
continue;
}

/** @var string $paramName */
$paramName = $this->getName($param->var);

$paramName = $this->getName($param);
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($paramName);

// already defined, lets skip it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Rector\Rector\AbstractRector;
use Rector\TypeDeclarationDocblocks\NodeFinder\ArrayDimFetchFinder;
use Rector\TypeDeclarationDocblocks\TagNodeAnalyzer\UsefulArrayTagNodeAnalyzer;
use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -30,7 +31,8 @@ public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly ArrayDimFetchFinder $arrayDimFetchFinder,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer
private readonly UsefulArrayTagNodeAnalyzer $usefulArrayTagNodeAnalyzer,
private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard
) {
}

Expand Down Expand Up @@ -102,9 +104,7 @@ public function refactor(Node $node): ?Node
continue;
}

/** @var string $paramName */
$paramName = $this->getName($param->var);

$paramName = $this->getName($param);
$paramTagValueNode = $phpDocInfo->getParamTagValueByName($paramName);

// already defined, lets skip it
Expand All @@ -117,6 +117,13 @@ public function refactor(Node $node): ?Node
continue;
}

// skip for now, not to create more error on incompatible parent @param doc override
if ($node instanceof ClassMethod && $this->parentClassMethodTypeOverrideGuard->hasParentClassMethod(
$node
)) {
continue;
}

$keyTypes = [];
foreach ($dimFetches as $dimFetch) {
// nothing to resolve here
Expand Down
2 changes: 1 addition & 1 deletion src/NodeAnalyzer/ParamAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function isNullable(Param $param): bool

public function isParamReassign(ClassMethod $classMethod, Param $param): bool
{
$paramName = (string) $this->nodeNameResolver->getName($param->var);
$paramName = $this->nodeNameResolver->getName($param);
return (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped($classMethod, function (Node $node) use (
$paramName
): bool {
Expand Down