Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Muqsit committed Oct 4, 2023
1 parent 6010c7e commit a152355
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/ParsedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, Scope>|null */
private ?array $scopes_cached = null;

/** @var Node[] */
private array $nodes_modified;

/**
* @param ScopeFactory $scope_factory
* @param NodeScopeResolver $scope_resolver
Expand Down Expand Up @@ -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;
Expand All @@ -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){
Expand Down
1 change: 1 addition & 0 deletions src/PreProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public function replaceIssetWithArrayKeyExists() : self{
}
}
}
return null;
});
}

Expand Down

0 comments on commit a152355

Please sign in to comment.