protected function execute(InputInterface $input, OutputInterface $output) { $targets = $input->getArgument('files'); foreach ($targets as $target) { if (!file_exists($target)) { throw new \Exception("'{$target}' is not a valid path"); } } $analyser = Analyser::buildDefault(); foreach ($targets as $target) { if (is_file($target)) { if (pathinfo($target, PATHINFO_EXTENSION) === 'php') { $analyser->analyseFile($target); } } else { $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($target, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST, \RecursiveIteratorIterator::CATCH_GET_CHILD); foreach ($iterator as $path => $target) { if ($target->isFile() && $target->getExtension() === 'php') { $analyser->analyseFile($path); } } } } $violations = $analyser->getReporter()->getViolations(); $this->printViolations($violations, $output); return count($violations) === 0 ? 0 : 1; }
public function testAnalyseValidCodeWithDefaultRuleset() { $analyser = Analyser::buildDefault(); $analyser->analyse('<?php class Foo {}'); $this->assertEquals([], $analyser->getReporter()->getViolations()); }