getIssuesCollector() public method

Get the IssuesCollector object.
public getIssuesCollector ( ) : IssuesCollector
return IssuesCollector
Example #1
0
 /**
  * @dataProvider provideTestParseAndDump
  *
  * @param $file
  * @param string $analyzer
  * @param string $expectedDump
  * @throws \PHPSA\Exception\RuntimeException
  * @throws \Webiny\Component\EventManager\EventManagerException
  */
 public function testParseAndDump($file, $analyzer, $expectedDump)
 {
     $compiler = new Compiler();
     $fileParser = new FileParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7, new \PhpParser\Lexer\Emulative(array('usedAttributes' => array('comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos')))), $compiler);
     $context = new Context(new \Symfony\Component\Console\Output\NullOutput(), $application = new Application(), $this->getEventManager($analyzer));
     $application->compiler = $compiler;
     $fileParser->parserFile($file, $context);
     $compiler->compile($context);
     $expectedArray = json_decode($expectedDump, true);
     $expectedType = $expectedArray[0]["type"];
     $issues = array_map(function (Issue $issue) {
         $location = $issue->getLocation();
         return ['type' => $issue->getCheckName(), 'message' => $issue->getDescription(), 'file' => $location->getFileName(), 'line' => $location->getLineStart()];
     }, $application->getIssuesCollector()->getIssues());
     foreach ($expectedArray as $check) {
         self::assertContains($check, $issues, $file);
         // every expected Issue is in the collector
     }
     foreach ($issues as $check) {
         if ($check["type"] == $expectedType) {
             self::assertContains($check, $expectedArray, $file);
             // there is no other issue in the collector with the same type
         }
     }
 }
Example #2
0
 /**
  * Creates a syntax error message.
  *
  * @param \PhpParser\Error $exception
  * @param string $filepath
  * @return bool
  */
 public function syntaxError(\PhpParser\Error $exception, $filepath)
 {
     $code = file($filepath);
     $this->output->writeln('<error>Syntax error:  ' . $exception->getMessage() . " in {$filepath} </error>");
     $this->output->writeln('');
     $issueCollector = $this->application->getIssuesCollector();
     $issueCollector->addIssue(new Issue('syntax-error', 'syntax-error', new IssueLocation($filepath, $exception->getStartLine() - 2)));
     $code = trim($code[$exception->getStartLine() - 2]);
     $this->output->writeln("<comment>\t {$code} </comment>");
     return true;
 }
Example #3
0
 /**
  * @covers \PHPSA\Application::getIssuesCollector
  */
 public function testGetIssueCollector()
 {
     $application = new Application();
     $this->assertInstanceOf('\\PHPSA\\IssuesCollector', $application->getIssuesCollector());
 }