Example #1
0
 public function projectEnd(Project $project)
 {
     if ($this->logfileWriter && 0 === strpos($this->logFormat, 'json')) {
         $options = $this->logFormat === 'json-pretty' ? JSON_PRETTY_PRINT : 0;
         $formatter = new Json($options);
         /** @noinspection PhpParamsInspection */
         $this->logfileWriter->write($formatter->formatReports($project->getAnalyzerReports()));
     }
 }
Example #2
0
 /**
  * Although this test seems redundant I use it to ensure that as far as it's
  * possible the analyzers do not negatively affect each other.
  */
 public function testAllAnalyzers()
 {
     $project = new Project(Null::getInstance());
     foreach (Util::scanDir(self::getAnalyzerTestsDir(), '/\\.phptest$/') as $file) {
         $project->addSplFileInfo(new \SplFileInfo($file));
     }
     $project->addAnalyzers(Project::getDefaultConfig());
     $project->analyze();
     $reports = $project->getAnalyzerReports();
     $this->assertSame(10, count($reports));
     $this->assertSame('Class Mfn\\PHP\\Analyzer\\Tests\\AbstractMethodMissing\\b misses the following abstract method: Mfn\\PHP\\Analyzer\\Tests\\AbstractMethodMissing\\a::b()', $reports[0]->getTimestampedReport()->getReport()->report());
     $this->assertSame('Class Mfn\\PHP\\Analyzer\\Tests\\InterfaceMethodMissing\\d misses the following interface method: Mfn\\PHP\\Analyzer\\Tests\\InterfaceMethodMissing\\a::c()', $reports[1]->getTimestampedReport()->getReport()->report());
     $this->assertSame('Declaration of Mfn\\PHP\\Analyzer\\Tests\\MethodDeclarationCompatibility\\b::c($a, $a) must be compatible with Mfn\\PHP\\Analyzer\\Tests\\MethodDeclarationCompatibility\\a::c(array $a = 1)', $reports[2]->getTimestampedReport()->getReport()->report());
     # Empty exception catch block reports
     $this->assertSame(27, $reports[3]->getSourceFragment()->getLineSegment()->getHighlightLine());
     $this->assertSame('Dynamic class instantiation with variable $foo in 003_dynamic_class_instantiation.phptest:26', $reports[4]->getTimestampedReport()->getReport()->report());
     $this->assertSame('Variable used in constructing raw SQL, is it escaped?', $reports[5]->getTimestampedReport()->getReport()->report());
     $this->assertSame(29, $reports[5]->getTimestampedReport()->getReport()->getSourceFragment()->getLineSegment()->getHighlightLine());
     $this->assertSame(30, $reports[6]->getTimestampedReport()->getReport()->getSourceFragment()->getLineSegment()->getHighlightLine());
     $this->assertSame(31, $reports[7]->getTimestampedReport()->getReport()->getSourceFragment()->getLineSegment()->getHighlightLine());
     # Empty exception catch block reports
     $this->assertSame(27, $reports[8]->getSourceFragment()->getLineSegment()->getHighlightLine());
     $this->assertSame(32, $reports[9]->getSourceFragment()->getLineSegment()->getHighlightLine());
 }
Example #3
0
 public function projectEnd(Project $project)
 {
     $this->write($this->json->formatReports($project->getAnalyzerReports()));
 }