getIssuesCollector() 공개 메소드

Get the IssuesCollector object.
public getIssuesCollector ( ) : IssuesCollector
리턴 IssuesCollector
예제 #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
         }
     }
 }
예제 #2
0
파일: Context.php 프로젝트: ovr/phpsa
 /**
  * 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;
 }
예제 #3
0
 /**
  * @covers \PHPSA\Application::getIssuesCollector
  */
 public function testGetIssueCollector()
 {
     $application = new Application();
     $this->assertInstanceOf('\\PHPSA\\IssuesCollector', $application->getIssuesCollector());
 }