function index(Config $config, OutputInterface $output, \RecursiveIteratorIterator $it2, $stubs = false) { $baseDir = $config->getBasePath(); $symbolTable = $config->getSymbolTable(); $indexer = new SymbolTableIndexer($symbolTable, $output); $traverser1 = new NodeTraverser(); $traverser1->addVisitor(new NameResolver()); $traverser2 = new NodeTraverser(); $traverser2->addVisitor($indexer); $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); $configArr = $config->getConfigArray(); $count = 0; foreach ($it2 as $file) { if (($file->getExtension() == "php" || $file->getExtension() == "inc") && $file->isFile()) { $name = Util::removeInitialPath($baseDir, $file->getPathname()); if (strpos($name, "phar://") === 0) { $name = str_replace(\Phar::running(), "", $name); while ($name[0] == '/') { $name = substr($name, 1); } $name = "phar://" . $name; } try { if (!$stubs && isset($configArr['ignore']) && is_array($configArr['ignore']) && Util::matchesGlobs($baseDir, $file->getPathname(), $configArr['ignore'])) { continue; } ++$count; $output->output(".", " - {$count}:" . $name); // If the $fileName is in our phar then make it a relative path so that files that we index don't // depend on the phar file existing in a particular directory. $fileData = file_get_contents($file->getPathname()); if ($config->shouldReindex()) { $symbolTable->removeFileFromIndex($file->getPathname()); } $indexer->setFilename($name); $stmts = $parser->parse($fileData); if ($stmts) { $traverser1->traverse($stmts); $traverser2->traverse($stmts); } } catch (Error $e) { $output->emitError(__CLASS__, $file, 0, ' Parse Error: ' . $e->getMessage() . "\n"); } } } return $count; }
function phase2(Config $config, OutputInterface $output, $toProcess) { $traverser1 = new NodeTraverser(); $traverser1->addVisitor(new DocBlockNameResolver()); $analyzer = new StaticAnalyzer($config->getBasePath(), $config->getSymbolTable(), $output, $config); $traverser2 = new NodeTraverser(); $traverser2->addVisitor(new TraitImportingVisitor($config->getSymbolTable())); $traverser3 = new NodeTraverser(); $traverser3->addVisitor($analyzer); $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); $processingCount = 0; foreach ($toProcess as $file) { try { $name = Util::removeInitialPath($config->getBasePath(), $file); $output->output(".", $name); $processingCount++; //echo " - $processingCount:" . $file . "\n"; $fileData = file_get_contents($file); $stmts = $parser->parse($fileData); if ($stmts) { $analyzer->setFile($name); $stmts = $traverser1->traverse($stmts); $stmts = $traverser2->traverse($stmts); $traverser3->traverse($stmts); } } catch (Error $e) { $output->emitError(__CLASS__, $file, 0, "Parse error", $e->getMessage()); } catch (\Guardrail\Exceptions\UnknownTraitException $e) { $output->emitError(__CLASS__, $file, 0, "Unknown trait error", $e->getMessage()); } } if ($output instanceof XUnitOutput) { // print_r($output->getCounts()); } return $output->getErrorCount() > 0 ? 1 : 0; }