src/AnalysableFile.php
/**
     * Analyses the file for all requested metrics.
     */
Analyses the file for all requested metrics.
Analyses the file for all requested metrics .
public function analyse() : AnalysisResult
    {
        $analysisResult = new AnalysisResult($this);
        try {
            $statements = $this->parser->parse(file_get_contents($this->file->getRealPath()));
        } catch (\PhpParser\Error $e) {
            $finding = new \NdB\PhpDocCheck\Findings\Error(
                new InvalidFileNode,
                $this,
                new \NdB\PhpDocCheck\Metrics\InvalidFile(),
                0
            );
            $analysisResult->addProgress($finding);
            $this->groupManager->addFinding($finding);
            return $analysisResult;
        }
        $traverser  = new \PhpParser\NodeTraverser();
        $traverser->addVisitor(new \PhpParser\NodeVisitor\NameResolver);
        $traverser->addVisitor(
            new \NdB\PhpDocCheck\NodeVisitors\ParentConnector()
        );
        $traverser->addVisitor(
            new \NdB\PhpDocCheck\NodeVisitors\DocParser()
        );
        foreach ($this->arguments->getOption('metric') as $metricSlug) {
            if (array_key_exists($metricSlug, $this->metrics)) {
                $metric = new $this->metrics[$metricSlug];
                $traverser->addVisitor(
                    new \NdB\PhpDocCheck\NodeVisitors\MetricChecker(
                        $analysisResult,
                        $this,
                        $metric,
                        $this->groupManager
                    )
                );
            }
        }
        $traverser->traverse($statements);
        return $analysisResult;
    }
public function analyse ( ) : AnalysisResult { $ analysisResult = new AnalysisResult ( $ this ) ; try { $ statements = $ this -> parser -> parse ( file_get_contents ( $ this -> file -> getRealPath ( ) ) ) ; } catch ( \ PhpParser \ Error $ e ) { $ finding = new \ NdB \ PhpDocCheck \ Findings \ Error ( new InvalidFileNode , $ this , new \ NdB \ PhpDocCheck \ Metrics \ InvalidFile ( ) , 0 ) ; $ analysisResult -> addProgress ( $ finding ) ; $ this -> groupManager -> addFinding ( $ finding ) ; return $ analysisResult ; } $ traverser = new \ PhpParser \ NodeTraverser ( ) ; $ traverser -> addVisitor ( new \ PhpParser \ NodeVisitor \ NameResolver ) ; $ traverser -> addVisitor ( new \ NdB \ PhpDocCheck \ NodeVisitors \ ParentConnector ( ) ) ; $ traverser -> addVisitor ( new \ NdB \ PhpDocCheck \ NodeVisitors \ DocParser ( ) ) ; foreach ( $ this -> arguments -> getOption ( 'metric' ) as $ metricSlug ) { if ( array_key_exists ( $ metricSlug , $ this -> metrics ) ) { $ metric = new $ this -> metrics [ $ metricSlug ] ; $ traverser -> addVisitor ( new \ NdB \ PhpDocCheck \ NodeVisitors \ MetricChecker ( $ analysisResult , $ this , $ metric , $ this -> groupManager ) ) ; } } $ traverser -> traverse ( $ statements ) ; return $ analysisResult ; }
Analyses the file for all requested metrics.
Analyses the file for all requested metrics .