mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Add support for view checking
This commit is contained in:
parent
91f39feea9
commit
f547f5e021
@ -44,6 +44,15 @@ class FileChecker
|
||||
self::$_file_checkers[$this->_file_name] = $this;
|
||||
}
|
||||
|
||||
public function checkWithClass($class_name)
|
||||
{
|
||||
$stmts = self::_getStatments($this->_file_name);
|
||||
|
||||
$class_method = new PhpParser\Node\Stmt\ClassMethod($class_name, ['stmts' => $stmts]);
|
||||
|
||||
(new ClassMethodChecker($class_method, '', [], $this->_file_name, $class_name))->check();
|
||||
}
|
||||
|
||||
public function _checkNamespace(PhpParser\Node\Stmt\Namespace_ $namespace, $check_classes)
|
||||
{
|
||||
foreach ($namespace->stmts as $stmt) {
|
||||
|
@ -39,6 +39,8 @@ class FunctionChecker
|
||||
$this->_class_extends = $class_extends;
|
||||
$this->_file_name = $file_name;
|
||||
|
||||
$this->_check_variables = substr($file_name, -4) === '.php';
|
||||
|
||||
$this->_absolute_class = ClassChecker::getAbsoluteClass($this->_class_name, $this->_namespace, []);
|
||||
|
||||
if ($function instanceof PhpParser\Node\Stmt\ClassMethod) {
|
||||
@ -158,6 +160,14 @@ class FunctionChecker
|
||||
else if ($stmt instanceof PhpParser\Node\Expr) {
|
||||
$this->_checkExpression($stmt, $vars_in_scope, $vars_possibly_in_scope);
|
||||
}
|
||||
else if ($stmt instanceof PhpParser\Node\Stmt\InlineHTML) {
|
||||
// do nothing
|
||||
}
|
||||
else if ($stmt instanceof PhpParser\Node\Stmt\Use_) {
|
||||
foreach ($stmt->uses as $use) {
|
||||
$this->_aliased_classes[$use->alias] = implode('\\', $use->name->parts);
|
||||
}
|
||||
}
|
||||
else {
|
||||
var_dump('Unrecognised statement');
|
||||
var_dump($stmt);
|
||||
@ -344,6 +354,9 @@ class FunctionChecker
|
||||
else if ($stmt instanceof PhpParser\Node\Expr\UnaryMinus) {
|
||||
$this->_checkExpression($stmt->expr, $vars_in_scope, $vars_possibly_in_scope);
|
||||
}
|
||||
else if ($stmt instanceof PhpParser\Node\Expr\UnaryPlus) {
|
||||
$this->_checkExpression($stmt->expr, $vars_in_scope, $vars_possibly_in_scope);
|
||||
}
|
||||
else if ($stmt instanceof PhpParser\Node\Expr\Isset_) {
|
||||
// do nothing
|
||||
}
|
||||
@ -464,6 +477,9 @@ class FunctionChecker
|
||||
else if ($stmt instanceof PhpParser\Node\Expr\ShellExec) {
|
||||
throw new CodeException('Use of shell_exec', $this->_file_name, $stmt->getLine());
|
||||
}
|
||||
else if ($stmt instanceof PhpParser\Node\Expr\Print_) {
|
||||
$this->_checkExpression($stmt->expr, $vars_in_scope, $vars_possibly_in_scope);
|
||||
}
|
||||
else {
|
||||
var_dump('Unrecognised expression');
|
||||
var_dump($stmt);
|
||||
|
Loading…
Reference in New Issue
Block a user