Skip to content

Commit 9ba6146

Browse files
Remove dedicated class
1 parent cb0a2e5 commit 9ba6146

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed

src/Rules/Comparison/ExpressionDependsOnThisHelper.php

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Rules/Comparison/ImpossibleCheckTypeHelper.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ private function isExpressionDependentOnTraitContext(Scope $scope, Expr $expr):
400400
return false;
401401
}
402402

403-
if (ExpressionDependsOnThisHelper::isExpressionDependentOnThis($expr)) {
403+
if (self::isExpressionDependentOnThis($expr)) {
404404
return true;
405405
}
406406

@@ -419,6 +419,32 @@ private function isExpressionDependentOnTraitContext(Scope $scope, Expr $expr):
419419
return false;
420420
}
421421

422+
public static function isExpressionDependentOnThis(Expr $expr): bool
423+
{
424+
if ($expr instanceof Expr\Variable && $expr->name === 'this') {
425+
return true;
426+
}
427+
428+
if ($expr instanceof Expr\PropertyFetch || $expr instanceof Expr\NullsafePropertyFetch) {
429+
return self::isExpressionDependentOnThis($expr->var);
430+
}
431+
432+
if ($expr instanceof Expr\MethodCall || $expr instanceof Expr\NullsafeMethodCall) {
433+
return self::isExpressionDependentOnThis($expr->var);
434+
}
435+
436+
if ($expr instanceof Expr\StaticPropertyFetch || $expr instanceof Expr\StaticCall) {
437+
if ($expr->class instanceof Expr) {
438+
return self::isExpressionDependentOnThis($expr->class);
439+
}
440+
441+
$className = $expr->class->toString();
442+
return in_array($className, ['self', 'static', 'parent'], true);
443+
}
444+
445+
return false;
446+
}
447+
422448
private static function isSpecified(Scope $scope, Expr $node, Expr $expr): bool
423449
{
424450
if ($expr === $node) {

0 commit comments

Comments
 (0)