1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Add support for view checking

This commit is contained in:
Matthew Brown 2016-01-11 14:21:29 -05:00
parent 91f39feea9
commit f547f5e021
2 changed files with 25 additions and 0 deletions

View File

@ -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) {

View File

@ -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);