Skip to content

Commit 97fed3e

Browse files
committed
HPB-4006 check for chained allowed methods
Signed-off-by: Tonko Mulder <tonko@tonkomulder.nl>
1 parent fbc9449 commit 97fed3e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Rules/ScopeRequestValidateMethods.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Foundation\Http\FormRequest;
66
use Illuminate\Http\Request as IlluminateRequest;
77
use Illuminate\Support\Collection;
8+
use Illuminate\Support\Stringable;
89
use PhpParser\Node;
910
use PhpParser\Node\Expr\MethodCall;
1011
use PHPStan\Analyser\Scope;
@@ -41,6 +42,10 @@ public function processNode(Node $node, Scope $scope): array
4142
return [];
4243
}
4344

45+
if ($this->usesValidatedMethod($node) && $this->isBlacklistedMethod($node->name->toString())) {
46+
return [];
47+
}
48+
4449
if (! $this->isBlacklistedMethod($node->name->toString())) {
4550
return [];
4651
}
@@ -85,6 +90,24 @@ private function hasFormRequestClass(Scope $scope): bool
8590
->isNotEmpty();
8691
}
8792

93+
/**
94+
* @phpstan-param MethodCall $node
95+
*/
96+
private function usesValidatedMethod(Node $node): bool
97+
{
98+
/** @var Node\Expr\Variable $var */
99+
$var = $node->var;
100+
if ($var->name instanceof Stringable) {
101+
return $var->name->toString() === 'safe';
102+
}
103+
104+
if ($var->name instanceof Node\Identifier) {
105+
return $var->name->toString() === 'safe';
106+
}
107+
108+
return $var->name === 'safe';
109+
}
110+
88111
/**
89112
* @phpstan-return ReflectionMethod[]
90113
* @throws ReflectionException

0 commit comments

Comments
 (0)