From a152355f14d93f1172e14664c23d2f08ab57920a Mon Sep 17 00:00:00 2001 From: Muqsit Date: Wed, 4 Oct 2023 13:09:07 +0000 Subject: [PATCH] Code cleanup --- src/ParsedFile.php | 17 +++++++---------- src/PreProcessor.php | 1 + 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/ParsedFile.php b/src/ParsedFile.php index 6151b74..5ccd8b0 100644 --- a/src/ParsedFile.php +++ b/src/ParsedFile.php @@ -23,16 +23,17 @@ use PHPStan\Analyser\ScopeFactory; use PHPStan\Type\ObjectType; use SplFileInfo; +use function method_exists; use function spl_object_id; final class ParsedFile{ - /** @var Node[] */ - private array $nodes_modified; - /** @var array|null */ private ?array $scopes_cached = null; + /** @var Node[] */ + private array $nodes_modified; + /** * @param ScopeFactory $scope_factory * @param NodeScopeResolver $scope_resolver @@ -81,10 +82,9 @@ public function visitWithScope(Closure ...$visitors) : void{ if($this->scopes_cached === null){ $this->scopes_cached = []; $mutating_scope = $this->scope_factory->create(ScopeContext::create($this->file->getPathname())); - $callback = function(Node $node, Scope $scope) : void{ + $this->scope_resolver->processNodes($this->nodes_modified, $mutating_scope, function(Node $node, Scope $scope) : void{ $this->scopes_cached[spl_object_id($node)] = $scope; - }; - $this->scope_resolver->processNodes($this->nodes_modified, $mutating_scope, $callback); + }); } if(!isset($this->scopes_cached[$id = spl_object_id($node)])){ return null; @@ -110,10 +110,7 @@ public function visitWithScope(Closure ...$visitors) : void{ * @phpstan-param Closure(MethodCall|StaticCall, Scope) : null|int|Node ...$visitors */ public function visitMethodCalls(string $class, string $method, Closure ...$visitors) : void{ - if(!method_exists($class, $method)){ - throw new InvalidArgumentException("Method {$class}::{$method} does not exist"); - } - + method_exists($class, $method) || throw new InvalidArgumentException("Method {$class}::{$method} does not exist"); $class_type = new ObjectType($class); $method = strtolower($method); $this->visitWithScope(static function(Node $node, Scope $scope) use($class_type, $method, $visitors){ diff --git a/src/PreProcessor.php b/src/PreProcessor.php index 5c4528b..db379f3 100644 --- a/src/PreProcessor.php +++ b/src/PreProcessor.php @@ -232,6 +232,7 @@ public function replaceIssetWithArrayKeyExists() : self{ } } } + return null; }); }