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 runChildProcesses(Config $config, OutputInterface $output, array $toProcess)
 {
     $error = false;
     $files = [];
     $groupSize = intval(count($toProcess) / $config->getProcessCount());
     for ($i = 0; $i < $config->getProcessCount(); ++$i) {
         $group = $i == $config->getProcessCount() - 1 ? array_slice($toProcess, $groupSize * $i) : array_slice($toProcess, $groupSize * $i, $groupSize);
         file_put_contents("scan.tmp.{$i}", implode("\n", $group));
         $cmd = escapeshellarg($GLOBALS['argv'][0]);
         $cmdLine = "php -d memory_limit=1G {$cmd} -a -s ";
         if ($config->getOutputFile()) {
             $outputFileName = $this->getMultipartFileName($config, $i);
             $cmdLine .= " -o " . escapeshellarg($outputFileName) . " ";
         }
         if ($config->getOutputLevel() == 1) {
             $cmdLine .= " -v ";
         }
         if ($config->getOutputLevel() == 2) {
             $cmdLine .= " -v -v ";
         }
         $cmdLine .= escapeshellarg($config->getConfigFileName()) . " " . escapeshellarg("scan.tmp.{$i}");
         $output->outputExtraVerbose($cmdLine . "\n");
         $file = popen($cmdLine, "r");
         $files[] = $file;
     }
     while (count($files) > 0) {
         $readFile = $files;
         $empty1 = $empty2 = null;
         $count = stream_select($readFile, $empty1, $empty2, 5);
         if ($count > 0) {
             foreach ($readFile as $index => $file) {
                 echo fread($file, 1000);
                 if (feof($file)) {
                     unset($files[array_search($file, $files)]);
                     if (!$error) {
                         $error = pclose($file) == 0;
                     }
                     $output->outputExtraVerbose("Child process completed\n");
                 }
             }
         } else {
             $output->output("T", "Timed out waiting for next file to scan");
         }
     }
     for ($i = 0; $i < $config->getProcessCount(); ++$i) {
         unlink("scan.tmp.{$i}");
     }
     return $error ? 1 : 0;
 }