Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure check isFirstClassCallable() before node->getArgs() on CallLike #4049

Merged
merged 3 commits into from
Jun 2, 2023
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
Expand Up @@ -68,6 +68,10 @@ public function refactor(Node $node): ?Node
{
$hasChanged = false;

if ($node->isFirstClassCallable()) {
return null;
}

foreach ($this->removeMethodCallParams as $removeMethodCallParam) {
if (! $this->isName($node->name, $removeMethodCallParam->getMethodName())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ private function refactorThrow(Throw_ $throw, Variable $catchedThrowableVariable
return null;
}

if ($new->isFirstClassCallable()) {
return null;
}

// exception is bundled
if (isset($new->getArgs()[$exceptionArgumentPosition])) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ private function refactorNew(New_ $new, Scope $scope): ?New_
return null;
}

if ($new->isFirstClassCallable()) {
return null;
}

$methodReflection = $this->reflectionResolver->resolveMethodReflectionFromNew($new);
if (! $methodReflection instanceof MethodReflection) {
return null;
Expand All @@ -136,6 +140,10 @@ private function refactorNew(New_ $new, Scope $scope): ?New_

private function refactorMethodCall(MethodCall|StaticCall $methodCall, Scope $scope): MethodCall|StaticCall|null
{
if ($methodCall->isFirstClassCallable()) {
return null;
}

$methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($methodCall);
if (! $methodReflection instanceof MethodReflection) {
return null;
Expand Down
4 changes: 4 additions & 0 deletions rules/CodeQuality/Rector/FuncCall/BoolvalToTypeCastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->isFirstClassCallable()) {
return null;
}

if (! $this->isName($node, 'boolval')) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->isFirstClassCallable()) {
return null;
}

if (! $this->isName($node, 'call_user_func')) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public function refactor(Node $node): ?Node
return null;
}

// if (! isset($node->getArgs[0])) {
// return null;
// }
if ($node->isFirstClassCallable()) {
return null;
}

$firstArg = $node->getArgs()[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (isset($node->getArgs()[2])) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (count($node->getArgs()) !== 2) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$firstArg = $node->getArgs()[0];

if (! $firstArg->value instanceof FuncCall) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (! isset($node->args[1])) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (! isset($node->getArgs()[0])) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (! isset($node->args[1])) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function refactor(Node $node): ?Node
/** @var FuncCall $secondExpr */
$secondExpr = $twoNodeMatch->getSecondExpr();

if ($secondExpr->isFirstClassCallable()) {
return null;
}

if (! isset($secondExpr->getArgs()[0])) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ private function resolveNewConditionNode(Expr $expr, bool $isNegated): ?BinaryOp

private function resolveCount(bool $isNegated, FuncCall $funcCall): Identical | Greater | null
{
if ($funcCall->isFirstClassCallable()) {
return null;
}

$countedType = $this->getType($funcCall->getArgs()[0]->value);

if ($countedType->isArray()->yes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ private function clearNotNullBeforeCount(Class_ $class, array $propertyNames): v
return false;
}

if ($node->isFirstClassCallable()) {
return false;
}

if (! $this->isName($node, 'count')) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (! isset($node->getArgs()[0])) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/CodingStyle/Rector/FuncCall/ConsistentImplodeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (count($node->getArgs()) === 1) {
// complete default value ''
$node->args[1] = $node->getArgs()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ private function matchCountFuncCallArgExpr(Expr $expr): ?Expr
return null;
}

if ($expr->isFirstClassCallable()) {
return null;
}

$firstArg = $expr->getArgs()[0];
return $firstArg->value;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/DeadCode/NodeManipulator/CountManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ private function isCountWithExpression(Expr $node, Expr $expr): bool
return false;
}

if ($node->isFirstClassCallable()) {
return false;
}

if (! isset($node->getArgs()[0])) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public function refactor(Node $node): ?FuncCall

private function processMysqlCreateDb(FuncCall $funcCall): ?FuncCall
{
if ($funcCall->isFirstClassCallable()) {
return null;
}

if (! isset($funcCall->getArgs()[0])) {
return null;
}
Expand All @@ -113,6 +117,10 @@ private function processMysqlCreateDb(FuncCall $funcCall): ?FuncCall

private function processMysqlDropDb(FuncCall $funcCall): ?FuncCall
{
if ($funcCall->isFirstClassCallable()) {
return null;
}

if (! isset($funcCall->getArgs()[0])) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (! isset($node->getArgs()[0])) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function getNodeTypes(): array
*/
public function refactor(Node $node): ?Node
{
if ($node->isFirstClassCallable()) {
return null;
}

foreach (self::FUNCTION_RENAME_MAP as $oldFunction => $newFunction) {
if (! $this->isName($node, $oldFunction)) {
continue;
Expand Down
4 changes: 4 additions & 0 deletions rules/Naming/Naming/VariableNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ private function resolveBareFuncCallArgumentName(
string $fallbackName,
string $suffix
): string {
if ($funcCall->isFirstClassCallable()) {
return '';
}

if (! isset($funcCall->getArgs()[0])) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (count($node->args) !== 1) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/Php70/Rector/FuncCall/EregToPregMatchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ private function shouldSkipFuncCall(FuncCall $funcCall): bool
return true;
}

if ($funcCall->isFirstClassCallable()) {
return true;
}

return ! isset($funcCall->getArgs()[0]);
}

Expand Down
4 changes: 4 additions & 0 deletions rules/Php70/Rector/FuncCall/MultiDirnameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ private function matchNestedDirnameFuncCall(FuncCall $funcCall): ?FuncCall
return null;
}

if ($funcCall->isFirstClassCallable()) {
return null;
}

$args = $funcCall->getArgs();
if (count($args) >= 3) {
return null;
Expand Down
4 changes: 4 additions & 0 deletions rules/Php71/IsArrayAndDualCheckToAble.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function processBooleanOr(BooleanOr $booleanOr, string $type, string $new
return null;
}

if ($funcCallExpr->isFirstClassCallable()) {
return null;
}

if (! isset($funcCallExpr->getArgs()[0])) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/Php71/Rector/FuncCall/CountOnNullRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ private function shouldSkipFuncCall(FuncCall $funcCall): bool
return true;
}

if ($funcCall->isFirstClassCallable()) {
return true;
}

// skip ternary in trait, as impossible to analyse
$trait = $this->betterNodeFinder->findParentType($funcCall, Trait_::class);
if ($trait instanceof Trait_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public function refactor(Node $node): ?array
/** @var FuncCall $eachFuncCall */
$eachFuncCall = $assign->expr;

if ($eachFuncCall->isFirstClassCallable()) {
return null;
}

if (! isset($eachFuncCall->getArgs()[0])) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/Php72/Rector/FuncCall/GetClassOnNullRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$firstArg = $node->getArgs()[0] ?? null;
if (! $firstArg instanceof Arg) {
return null;
Expand Down
4 changes: 4 additions & 0 deletions rules/Php72/Rector/FuncCall/StringifyDefineRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

if (! isset($node->getArgs()[0])) {
return null;
}
Expand Down
4 changes: 4 additions & 0 deletions rules/Php72/Rector/FuncCall/StringsAssertNakedRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public function refactor(Node $node): ?Node
return null;
}

if ($node->isFirstClassCallable()) {
return null;
}

$firstArg = $node->getArgs()[0];

$firstArgValue = $firstArg->value;
Expand Down
4 changes: 4 additions & 0 deletions rules/Php72/Rector/While_/WhileEachToForeachRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function refactor(Node $node): ?Node
/** @var FuncCall $eachFuncCall */
$eachFuncCall = $assignNode->expr;

if ($eachFuncCall->isFirstClassCallable()) {
return null;
}

/** @var List_ $listNode */
$listNode = $assignNode->var;

Expand Down
Loading
Loading