diff --git a/lib/FileChecker.php b/lib/FileChecker.php index 0a8d76581..9d4c4ba7a 100644 --- a/lib/FileChecker.php +++ b/lib/FileChecker.php @@ -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) { diff --git a/lib/FunctionChecker.php b/lib/FunctionChecker.php index 4664afe40..0ff60d65b 100644 --- a/lib/FunctionChecker.php +++ b/lib/FunctionChecker.php @@ -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);