/** * parses all given files for classes and interfaces that are defined or used in this * files. * * @param array $files */ public function parseFilesForClassesAndInterfaces($files) { $parserFactory = new ParserFactory(); $parser = $parserFactory->create(ParserFactory::PREFER_PHP7); $progressbar = new Progressbar($this->output, count($files)); foreach ($files as $file) { $namespace = (string) new NamespaceString($this->namespaceVendor, $this->root, $file); $originalFileContent = $this->filesystem->getFile($file); try { $stmts = $parser->parse($originalFileContent); $firstStatement = $stmts[0]; if ($firstStatement instanceof Namespace_) { $namespaceOfFile = implode('\\', $firstStatement->name->parts); if ($namespace !== $namespaceOfFile) { $this->foundError = true; $this->output->addError('Namespace does not match folder structure, got ' . $namespaceOfFile . ' expected ' . $namespace, $file, $firstStatement->getLine()); } } } catch (Error $e) { $this->foundError = true; $this->output->addError('Parse Error: ' . $e->getMessage(), $file, 1); } $fileContent = $this->cleanContent($originalFileContent); $this->parseDefinedEntities($file, $namespace, $fileContent, $originalFileContent); $this->parseUsedEntities($file, $namespace, $fileContent, $originalFileContent); $this->parseUseStatements($file, $namespace, $fileContent, $originalFileContent); $progressbar->step(); } }
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $configFile = $input->getArgument('config'); if (!$configFile) { throw new \Exception('Config argument needed'); } $filesystem = new FilesystemAccess(null); $config = new Config($filesystem); $config->loadConfig($configFile); $config = $config->getConfig(); $config->folders->root = realpath($config->folders->root); $filesystem->setRoot($config->folders->root); $directoryScanner = new DirectoryScanner($filesystem, $config->folders->root); foreach ($config->folders->include as $include) { $directoryScanner->includeDirectory($include); } foreach ($config->folders->exclude as $exclude) { $directoryScanner->excludeDirectory($exclude); } foreach ($config->filetypes->include as $include) { $directoryScanner->includeFiletype($include); } foreach ($config->filetypes->exclude as $exclude) { $directoryScanner->excludeFiletype($exclude); } $files = $directoryScanner->getFiles(); $outputClass = new ChainedOutput($output); foreach ($config->output as $outputConfiguration) { $outputClass->addOutputClass($outputConfiguration->class, $outputConfiguration->parameter); } $classScanner = new ClassScanner($filesystem, $config->folders->root, $config->vendor, $outputClass); $classModifier = new NamespaceDependencyChecker($filesystem, $classScanner, $config->vendor, $config->folders->root, $outputClass); $classModifier->analyze($files); $outputClass->printAll(); $outputClass->writeln(\PHP_Timer::resourceUsage()); if ($classScanner->foundError || $classModifier->foundError) { return 1; } else { return 0; } }