/** * @param array $args */ public function handle(array $args) { $this->cli->out(sprintf('PHPAssumptions analyser v%s by @rskuipers', Cli::VERSION))->br(); try { $this->cli->arguments->parse($args); } catch (\Exception $e) { $this->cli->usage($args); return; } switch ($this->cli->arguments->get('format')) { case 'xml': $output = new XmlOutput($this->cli, $this->cli->arguments->get('output')); break; default: $output = new PrettyOutput($this->cli); break; } $nodeTraverser = new NodeTraverser(); $analyser = new Analyser($this->parser, $nodeTraverser); $nodeTraverser->addVisitor(new NodeVisitor($analyser, new Detector())); $target = $this->cli->arguments->get('path'); $targets = []; if (is_file($target)) { $targets[] = $target; } else { $directory = new \RecursiveDirectoryIterator($target); $iterator = new \RecursiveIteratorIterator($directory); $regex = new \RegexIterator($iterator, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH); foreach ($regex as $file) { $targets[] = $file[0]; } } $result = $analyser->analyse($targets); $output->output($result); }
/** * @test */ public function itShouldCallScanAndNotWriteOnFailure() { $this->detector->scan($this->node)->shouldBeCalled()->willReturn(false); $this->detector->isBoolExpression($this->node)->shouldBeCalled()->willReturn(true); $this->analyser->foundAssumption(Argument::any(), Argument::any())->shouldNotBeCalled(); $this->analyser->foundBoolExpression()->shouldBeCalled(); $this->nodeVisitor->enterNode($this->node->reveal()); }
/** * @param Node $node * @return false|null|Node|\PhpParser\Node[]|void */ public function enterNode(Node $node) { if ($this->detector->isBoolExpression($node)) { $this->analyser->foundBoolExpression(); } if ($this->detector->scan($node)) { $this->analyser->foundAssumption($node->getLine()); } }
/** * @test */ public function itShouldAnalyseAllFiles() { $files = [fixture('MyClass.php')]; $nodes = [$this->node]; $parseRes = $this->parser->parse(Argument::type('string')); $this->parser->parse(Argument::type('string'))->shouldBeCalled()->willReturn($nodes); $this->nodeTraverser->traverse($nodes)->shouldBeCalled(); $this->analyser->analyse($files); }