use Mfn\PHP\Analyzer\Analyzers\ObjectGraph\Helper;
use Mfn\PHP\Analyzer\Analyzers\ObjectGraph\ObjectGraph;
use Mfn\PHP\Analyzer\Analyzers\Parser;
use Mfn\PHP\Analyzer\Logger\Stdout;
use Mfn\PHP\Analyzer\Project;
use Mfn\PHP\Analyzer\Util\Util;
use PhpParser\Lexer;
require_once __DIR__ . '/../vendor/autoload.php';
error_reporting(E_ALL);
Util::installMinimalError2ExceptionHandler();
$projectRealPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . '..');
# Use analyzer to gather the object graph
$project = new Project(new Stdout());
$project->addSplFileInfos(Util::scanDir(__DIR__ . '/../lib/'));
$project->addAnalyzers([new Parser(new \PhpParser\Parser(new Lexer())), new NameResolver(), $objectGraph = new ObjectGraph()]);
$project->analyze();
$helper = new Helper($objectGraph);
$className = 'Mfn\\PHP\\Analyzer\\Analyzers\\Analyzer';
$class = $objectGraph->getClassByFqn($className);
if (NULL === $class) {
    throw new \RuntimeException("Unable to find class {$className}");
}
unset($className);
$descendants = $helper->findExtends($class, true);
sort($descendants);
/** @var string[] $index */
$index = [];
$index[] = '# Built-in / available Analyzers';
$index[] = '';
foreach ($descendants as $class) {
    $doccomment = $class->getClass()->getDocComment();
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 main()
 {
     if (NULL === $this->filesets) {
         throw new \BuildException('No fileset provided');
     }
     $project = new Project(new Phing($this));
     $project->addListener($listener = new PhingListener($this));
     $analyzers = NULL !== $this->getConfigFile() ? require $this->getConfigFile() : Project::getDefaultConfig();
     $project->addAnalyzers($analyzers);
     # Add files
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         /** @var \PhingFile $fromDir */
         $fromDir = $fs->getDir($this->project);
         /** @var  $files */
         $files = $ds->getIncludedFiles();
         foreach ($files as $file) {
             $fileName = $fromDir->getAbsolutePath() . DIRECTORY_SEPARATOR . $file;
             $this->log('Adding file ' . $fileName, \Project::MSG_VERBOSE);
             $project->addSplFileInfo(new \SplFileInfo($fileName));
         }
     }
     $project->analyze();
     $buildErrorMessage = $listener->getBuildErrorMessage();
     if ($this->haltonerror && !empty($buildErrorMessage)) {
         throw new \BuildException($buildErrorMessage);
     }
 }