/**
* This first pass parses code and looks for the subset
* of issues that can be found without having to have
* an understanding of the entire code base.
*
* @param CodeBase $code_base
* The CodeBase represents state across the entire
* code base. This is a mutable object which is
* populated as we parse files
*
* @param string $file_path
* The full path to a file we'd like to parse
*
* @return Context
*/
public static function parseFile(CodeBase $code_base, string $file_path) : Context
{
$context = (new Context())->withFile($file_path);
// Convert the file to an Abstract Syntax Tree
// before passing it on to the recursive version
// of this method
$node = \ast\parse_file($file_path, Config::get()->ast_version);
if (Config::get()->dump_ast) {
echo $file_path . "\n" . str_repeat("¯", strlen($file_path)) . "\n";
Debug::printNode($node);
return $context;
}
if (empty($node)) {
Issue::emit(Issue::EmptyFile, $file_path, 0, $file_path);
return $context;
}
return self::parseNodeInContext($code_base, $context, $node);
}