mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Fix #251 - allow Psalm to analyse Wordpress
This commit is contained in:
parent
c395930a06
commit
3c6a8a0b24
@ -242,20 +242,8 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
$leftover_stmts = [];
|
||||
|
||||
foreach ($stmts as $stmt) {
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\ClassLike && $stmt->name) {
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\Class_) {
|
||||
$class_checker = new ClassChecker($stmt, $this, $stmt->name);
|
||||
|
||||
$fq_class_name = $class_checker->getFQCLN();
|
||||
|
||||
$this->class_checkers_to_analyze[strtolower($fq_class_name)] = $class_checker;
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Interface_) {
|
||||
$class_checker = new InterfaceChecker($stmt, $this, $stmt->name);
|
||||
|
||||
$fq_class_name = $class_checker->getFQCLN();
|
||||
|
||||
$this->interface_checkers_to_analyze[$fq_class_name] = $class_checker;
|
||||
}
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\ClassLike) {
|
||||
$this->populateClassLikeCheckers($stmt);
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Namespace_) {
|
||||
$namespace_name = $stmt->name ? implode('\\', $stmt->name->parts) : '';
|
||||
|
||||
@ -270,6 +258,14 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\GroupUse) {
|
||||
$this->visitGroupUse($stmt);
|
||||
} elseif (!($stmt instanceof PhpParser\Node\Stmt\Function_)) {
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\If_) {
|
||||
foreach ($stmt->stmts as $if_stmt) {
|
||||
if ($if_stmt instanceof PhpParser\Node\Stmt\ClassLike) {
|
||||
$this->populateClassLikeCheckers($if_stmt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$leftover_stmts[] = $stmt;
|
||||
}
|
||||
}
|
||||
@ -277,6 +273,30 @@ class FileChecker extends SourceChecker implements StatementsSource
|
||||
return $leftover_stmts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function populateClassLikeCheckers(PhpParser\Node\Stmt\ClassLike $stmt)
|
||||
{
|
||||
if (!$stmt->name) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\Class_) {
|
||||
$class_checker = new ClassChecker($stmt, $this, $stmt->name);
|
||||
|
||||
$fq_class_name = $class_checker->getFQCLN();
|
||||
|
||||
$this->class_checkers_to_analyze[strtolower($fq_class_name)] = $class_checker;
|
||||
} elseif ($stmt instanceof PhpParser\Node\Stmt\Interface_) {
|
||||
$class_checker = new InterfaceChecker($stmt, $this, $stmt->name);
|
||||
|
||||
$fq_class_name = $class_checker->getFQCLN();
|
||||
|
||||
$this->interface_checkers_to_analyze[$fq_class_name] = $class_checker;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fq_class_name
|
||||
* @param ClassChecker $class_checker
|
||||
|
Loading…
Reference in New Issue
Block a user