public function scanDirectory(PackageVersion $rootPackageVersion, $directory)
 {
     $this->logger->info(sprintf('Scanning directory "%s" for files', $directory));
     $files = FileCollection::createFromDirectory($directory, '*.php');
     $this->logger->info(sprintf('Found "%d" files.', count($files)));
     $this->scan($rootPackageVersion, $files);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dir = $input->getArgument('dir');
     if (extension_loaded('xdebug')) {
         $output->writeln('<error>It is highly recommended to disable the XDebug extension before invoking this command.</error>');
     }
     $output->writeln('Scanning directory <info>' . $dir . '</info>');
     $files = FileCollection::createFromDirectory($dir, '*.php', array('paths' => $input->getOption('include-pattern'), 'excluded_paths' => $input->getOption('exclude-pattern')));
     $output->writeln(sprintf('found <info>%d files</info>', count($files)));
     if (count($files) > 100) {
         $output->writeln('<comment>Caution: You are trying to scan a lot of files; this might be slow. For bigger libraries, consider setting up a dedicated platform or using scrutinizer-ci.com.</comment>');
     }
     $output->writeln('Starting analysis...');
     $analyzer = Analyzer::create(TestUtils::createTestEntityManager());
     $analyzer->setLogger(new OutputLogger($output, $input->getOption('verbose')));
     $analyzer->analyze($files);
     if ($input->getOption('filter-pattern')) {
         $files = $files->filter($input->getOption('filter-pattern'));
     }
     switch ($input->getOption('format')) {
         case 'plain':
             $formatter = new OutputFormatter\TextFormatter();
             break;
         default:
             $formatter = new OutputFormatter\SerializerFormatter($input->getOption('output-file'), $input->getOption('format'));
             break;
     }
     $formatter->write($output, $files);
 }
 public function testMergeCollections()
 {
     $col = FileCollection::createFromZipFile(__DIR__ . '/Fixture/zip-file.zip');
     $col2 = FileCollection::createFromDirectory(__DIR__ . '/Fixture/DirWithSomeFiles');
     $merged = $col->merge($col2);
     $this->assertCount(3, $col);
     $files = $col->all();
     $this->assertArrayHasKey('A.php', $files);
     $this->assertArrayHasKey('Sub-Dir/B.php', $files);
     $this->assertArrayHasKey('text.txt', $files);
 }
 private function dumpComments(FileCollection $col)
 {
     $files = $col->all();
     ksort($files);
     $content = '';
     foreach ($files as $file) {
         if (!$file->hasComments()) {
             continue;
         }
         $content .= $file->getName() . "\n";
         $content .= "---------------------------------------------------\n";
         foreach ($file->getComments() as $line => $lineComments) {
             foreach ($lineComments as $comment) {
                 /** @var $comment Comment */
                 $content .= "Line {$line}: " . $comment->getKey() . "\n";
             }
         }
         $content .= "\n";
     }
     return $content;
 }