Skip to content

Commit

Permalink
fix getArgs() missing in phpstan scoped version in rector-src packages (
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 30, 2021
1 parent e5859d6 commit ffa3915
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions phpstan.neon
Expand Up @@ -498,3 +498,8 @@ parameters:

# false positive - class_exists check is right above it
- '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class\-string<Rector\\RectorInstaller\\GeneratedConfig\>\|Rector\\RectorInstaller\\GeneratedConfig, string given#'

# waits for phpstan upgrade to php-parser 4.13
- '#Access to an undefined property PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder\:\:\$value#'
- '#(.*?), array<PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder\> given#'
- '#(.*?) but returns array<int, PhpParser\\Node\\Arg\|PhpParser\\Node\\VariadicPlaceholder\>#'
2 changes: 1 addition & 1 deletion rules/Arguments/ArgumentDefaultValueReplacer.php
Expand Up @@ -100,7 +100,7 @@ private function processArgs(
) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) {
$expr->args[$position] = $this->normalizeValueToArgument($replaceArgumentDefaultValue->getValueAfter());
} elseif (is_array($replaceArgumentDefaultValue->getValueBefore())) {
$newArgs = $this->processArrayReplacement($expr->getArgs(), $replaceArgumentDefaultValue);
$newArgs = $this->processArrayReplacement($expr->args, $replaceArgumentDefaultValue);

if ($newArgs) {
$expr->args = $newArgs;
Expand Down
Expand Up @@ -71,7 +71,7 @@ public function refactor(Node $node): ?Node
return null;
}

$args = $node->getArgs();
$args = $node->args;
if (! isset($args[3])) {
return null;
}
Expand Down
Expand Up @@ -117,7 +117,7 @@ public function refactor(Node $node): ?Node

private function processArgs(FuncCall | MethodCall | StaticCall | New_ $node): ?Node
{
$args = $node->getArgs();
$args = $node->args;
if ($args === []) {
return null;
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ public function refactor(Node $node): ?Node

private function createSubstrCompareFuncCall(FuncCall $funcCall): FuncCall
{
$args = $funcCall->getArgs();
$args = $funcCall->args;

$strlenFuncCall = $this->createStrlenFuncCall($args[1]->value);
$args[] = new Arg(new UnaryMinus($strlenFuncCall));
Expand Down
Expand Up @@ -81,7 +81,7 @@ private function execute($a = null, $b = null)
*/
public function refactor(Node $node): ?Node
{
$args = $node->getArgs();
$args = $node->args;
if ($this->shouldSkip($args)) {
return null;
}
Expand Down
Expand Up @@ -131,10 +131,9 @@ public function refactor(Node $node): ?Node
continue;
}

$args = $node->getArgs();
$args = $node->args;
if (
$args === []
|| ! $this->isProbablyMysql($args[0]->value)
$args === [] || ! $this->isProbablyMysql($args[0]->value)
) {
$connectionVariable = $this->findConnectionVariable($node);

Expand All @@ -144,7 +143,7 @@ public function refactor(Node $node): ?Node
return null;
}

$node->args = array_merge([new Arg($connectionVariable)], $node->getArgs());
$node->args = array_merge([new Arg($connectionVariable)], $node->args);
}

$node->name = new Name($newFunction);
Expand Down
2 changes: 1 addition & 1 deletion rules/Php70/Rector/FuncCall/CallUserMethodRector.php
Expand Up @@ -65,7 +65,7 @@ public function refactor(Node $node): ?Node
$newName = self::OLD_TO_NEW_FUNCTIONS[$this->getName($node)];
$node->name = new Name($newName);

$oldArgs = $node->getArgs();
$oldArgs = $node->args;

unset($node->args[1]);

Expand Down
2 changes: 1 addition & 1 deletion rules/Php70/Rector/FuncCall/MultiDirnameRector.php
Expand Up @@ -82,7 +82,7 @@ private function matchNestedDirnameFuncCall(FuncCall $funcCall): ?FuncCall
return null;
}

$args = $funcCall->getArgs();
$args = $funcCall->args;
if (count($args) >= 3) {
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions rules/Php73/Rector/FuncCall/SetCookieRector.php
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\VariadicPlaceholder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand Down Expand Up @@ -116,13 +117,13 @@ private function shouldSkip(FuncCall $funcCall): bool
}

/**
* @return Arg[]
* @return Arg[]|VariadicPlaceholder[]
*/
private function composeNewArgs(FuncCall $funcCall): array
{
$items = [];

$args = $funcCall->getArgs();
$args = $funcCall->args;

$newArgs = [];
$newArgs[] = $args[0];
Expand Down
Expand Up @@ -144,12 +144,12 @@ private function refactorNew(New_ $new): ?New_
return null;
}

$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $new->getArgs());
$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent($methodReflection, $new->args);
if ($expectedArgOrParamOrder === null) {
return null;
}

$new->args = $this->argumentSorter->sortArgsByExpectedParamOrder($new->getArgs(), $expectedArgOrParamOrder);
$new->args = $this->argumentSorter->sortArgsByExpectedParamOrder($new->args, $expectedArgOrParamOrder);
$new->setAttribute(self::ALREADY_SORTED, true);

return $new;
Expand All @@ -164,14 +164,14 @@ private function refactorMethodCall(MethodCall $methodCall): ?MethodCall

$expectedArgOrParamOrder = $this->resolveExpectedArgParamOrderIfDifferent(
$methodReflection,
$methodCall->getArgs()
$methodCall->args
);
if ($expectedArgOrParamOrder === null) {
return null;
}

$newArgs = $this->argumentSorter->sortArgsByExpectedParamOrder(
$methodCall->getArgs(),
$methodCall->args,
$expectedArgOrParamOrder
);

Expand Down
Expand Up @@ -223,7 +223,7 @@ private function createPropertyFetchMockVariableAssign(Param $param, Name $name)

private function createIsTypeOrIsInstanceOf(StaticCall $staticCall): MethodCall
{
$args = $staticCall->getArgs();
$args = $staticCall->args;
$type = $this->valueResolver->getValue($args[0]->value);

$name = $this->typeAnalyzer->isPhpReservedType($type) ? 'isType' : 'isInstanceOf';
Expand Down
Expand Up @@ -147,7 +147,7 @@ public function refactor(Node $node): ?Node

$this->processMatchersKeys($node);

$args = $node->getArgs();
$args = $node->args;
foreach (self::NEW_METHOD_TO_OLD_METHODS as $newMethod => $oldMethods) {
if (! $this->isNames($node->name, $oldMethods)) {
continue;
Expand Down

0 comments on commit ffa3915

Please sign in to comment.