Example #1
0
 protected function describeAnalysis(Analysis $analysis, array $options = array())
 {
     $output = $options['output'];
     $xml = new \DOMDocument('1.0', 'UTF-8');
     $xpath = new \DOMXPath($xml);
     $xml->formatOutput = true;
     $xml->preserveWhiteSpace = true;
     $pmd = $xml->createElement('pmd');
     $pmd->setAttribute('timestamp', $analysis->getEndAt()->format('c'));
     $xml->appendChild($pmd);
     foreach ($analysis->getViolations() as $violation) {
         /**
          * @var $violation \SensioLabs\Insight\Sdk\Model\Violation
          */
         $filename = $violation->getResource();
         $nodes = $xpath->query(sprintf('//file[@name="%s"]', $filename));
         if ($nodes->length > 0) {
             $node = $nodes->item(0);
         } else {
             $node = $xml->createElement('file');
             $node->setAttribute('name', $filename);
             $pmd->appendChild($node);
         }
         $violationNode = $xml->createElement('violation', $violation->getMessage());
         $node->appendChild($violationNode);
         $violationNode->setAttribute('beginline', $violation->getLine());
         $violationNode->setAttribute('endline', $violation->getLine());
         $violationNode->setAttribute('rule', $violation->getTitle());
         $violationNode->setAttribute('ruleset', $violation->getCategory());
         $violationNode->setAttribute('priority', $this->getPriority($violation));
     }
     $output->writeln($xml->saveXML());
 }
Example #2
0
    protected function describeAnalysis(Analysis $analysis, array $options = array())
    {
        $output = $options['output'];
        if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
            $output->write(sprintf('Began at: <comment>%s</comment>', $analysis->getBeginAt()->format('Y-m-d h:i:s')));
        }
        if (!$analysis->isFinished()) {
            if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
                $output->writeln('');
            }
            $output->writeln('The analysis is not finished yet.');
            return;
        }
        if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
            $output->write(sprintf(' Ended at: <comment>%s</comment>', $analysis->getEndAt()->format('Y-m-d h:i:s')));
            $output->writeln(sprintf(' Real duration: <comment>%s</comment>.', $analysis->getEndAt()->format('Y-m-d h:i:s')));
            $output->writeln('');
        }
        $output->write(sprintf('The project has <comment>%d violations</comment>, it got the <comment>%s grade</comment>.', $analysis->getNbViolations(), $analysis->getGrade()));
        $grades = $analysis->getGrades();
        $bestGrade = end($grades);
        if ($bestGrade == $analysis->getGrade()) {
            $output->writeln('');
            return;
        }
        $output->writeln(sprintf(' <comment>%d hours</comment> to get the <comment>%s grade</comment> and %d hours to get the %s grade', $analysis->getRemediationCostForNextGrade(), $analysis->getNextGrade(), $analysis->getRemediationCost(), $bestGrade));
        $output->writeln('');
        if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() && $analysis->getViolations()) {
            $template = <<<EOL
Resource: <comment>{{ resource }}:{{ line }}</comment>
Category: <comment>{{ category }}</comment> Severity: <comment>{{ severity }}</comment>
Title:    <comment>{{ title }}</comment>
Message:  <comment>{{ message }}</comment>

EOL;
            foreach ($analysis->getViolations() as $violation) {
                $output->writeln(strtr($template, array('{{ resource }}' => $violation->getResource(), '{{ line }}' => $violation->getLine(), '{{ category }}' => $violation->getCategory(), '{{ severity }}' => $violation->getSeverity(), '{{ title }}' => $violation->getTitle(), '{{ message }}' => $violation->getMessage())));
            }
        }
        foreach ($analysis->getLinks() as $link) {
            if ('self' == $link->getRel() && 'text/html' == $link->getType()) {
                $output->writeln(sprintf('You can get the full report at <info>%s</info>', $link->getHref()));
                break;
            }
        }
    }