diff --git a/Cli/Command/AnalysisCommand.php b/Cli/Command/AnalysisCommand.php index bf81799..0a24720 100644 --- a/Cli/Command/AnalysisCommand.php +++ b/Cli/Command/AnalysisCommand.php @@ -28,6 +28,7 @@ protected function configure() ->addArgument('project-uuid', InputArgument::REQUIRED) ->addOption('format', null, InputOption::VALUE_REQUIRED, 'To output in other formats', 'txt') ->addOption('fail-condition', null, InputOption::VALUE_REQUIRED, '') + ->addOption('show-ignored-violations', null, InputOption::VALUE_NONE, 'Show ignored violations') ->setDescription('Show the last project analysis') ; } @@ -44,7 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $helper = new DescriptorHelper($api->getSerializer()); - $helper->describe($output, $analysis, $input->getOption('format')); + $helper->describe($output, $analysis, $input->getOption('format'), $input->getOption('show-ignored-violations')); if ('txt' === $input->getOption('format') && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { $output->writeln(''); @@ -74,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $vars = array( 'analysis' => $analysis, - 'counts' => (object) $counts, + 'counts' => (object) $counts, ); if ($el->evaluate($expr, $vars)) { diff --git a/Cli/Command/AnalyzeCommand.php b/Cli/Command/AnalyzeCommand.php index db416fc..ff0104f 100644 --- a/Cli/Command/AnalyzeCommand.php +++ b/Cli/Command/AnalyzeCommand.php @@ -27,6 +27,7 @@ protected function configure() ->addArgument('project-uuid', InputArgument::REQUIRED) ->addOption('format', null, InputOption::VALUE_REQUIRED, 'To output in other formats', 'txt') ->addOption('reference', null, InputOption::VALUE_REQUIRED, 'The git reference to analyze') + ->addOption('show-ignored-violations', null, InputOption::VALUE_NONE, 'Show ignored violations') ->setDescription('Analyze a project') ; } @@ -54,7 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output) usleep(200000); - $position++; + ++$position; } $analysis = $api->getAnalysis($projectUuid, $analysis->getNumber()); @@ -65,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $helper = new DescriptorHelper($api->getSerializer()); - $helper->describe($output, $analysis, $input->getOption('format')); + $helper->describe($output, $analysis, $input->getOption('format'), $input->getOption('show-ignored-violations')); if ('txt' === $input->getOption('format') && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { $output->writeln(''); diff --git a/Cli/Command/ProjectsCommand.php b/Cli/Command/ProjectsCommand.php index aec852e..810350f 100644 --- a/Cli/Command/ProjectsCommand.php +++ b/Cli/Command/ProjectsCommand.php @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $nbPage = ceil($projectsResource->getTotal() / 10); $page = 1; while ($page < $nbPage) { - $page++; + ++$page; $projects = array_merge($projects, $api->getProjects($page)->getProjects()); } diff --git a/Cli/Configuration.php b/Cli/Configuration.php index f36aec5..2d3fd75 100644 --- a/Cli/Configuration.php +++ b/Cli/Configuration.php @@ -111,7 +111,7 @@ private function getStoragePath() } } - if (!is_dir($storagePath) && ! @mkdir($storagePath, 0777, true)) { + if (!is_dir($storagePath) && !@mkdir($storagePath, 0777, true)) { throw new \RuntimeException(sprintf('The directory "%s" does not exist and could not be created.', $storagePath)); } diff --git a/Cli/Descriptor/AbstractDescriptor.php b/Cli/Descriptor/AbstractDescriptor.php index 3bf93ba..753420c 100644 --- a/Cli/Descriptor/AbstractDescriptor.php +++ b/Cli/Descriptor/AbstractDescriptor.php @@ -12,12 +12,19 @@ namespace SensioLabs\Insight\Cli\Descriptor; use SensioLabs\Insight\Sdk\Model\Analysis; +use SensioLabs\Insight\Sdk\Model\Violation; abstract class AbstractDescriptor { public function describe($object, array $options = array()) { if ($object instanceof Analysis) { + if (!$options['show_ignored_violations']) { + $object->getViolations()->filter(function (Violation $v) { + return !$v->isIgnored(); + }); + } + return $this->describeAnalysis($object, $options); } diff --git a/Cli/Descriptor/PmdDescriptor.php b/Cli/Descriptor/PmdDescriptor.php index 0aba393..ffe8c54 100644 --- a/Cli/Descriptor/PmdDescriptor.php +++ b/Cli/Descriptor/PmdDescriptor.php @@ -7,20 +7,20 @@ class PmdDescriptor extends AbstractDescriptor { - const PHPMD_PRIORITY_HIGH = 1; - const PHPMD_PRIORITY_MEDIUM_HIGH = 2; - const PHPMD_PRIORITY_MEDIUM = 3; - const PHPMD_PRIORITY_MEDIUM_LOW = 4; - const PHPMD_PRIORITY_LOW = 5; + const PHPMD_PRIORITY_HIGH = 1; + const PHPMD_PRIORITY_MEDIUM_HIGH = 2; + const PHPMD_PRIORITY_MEDIUM = 3; + const PHPMD_PRIORITY_MEDIUM_LOW = 4; + const PHPMD_PRIORITY_LOW = 5; protected function describeAnalysis(Analysis $analysis, array $options = array()) { $output = $options['output']; - $xml = new \DOMDocument('1.0', 'UTF-8'); + $xml = new \DOMDocument('1.0', 'UTF-8'); $xpath = new \DOMXPath($xml); - $xml->formatOutput = true; + $xml->formatOutput = true; $xml->preserveWhiteSpace = true; $pmd = $xml->createElement('pmd'); @@ -31,7 +31,7 @@ protected function describeAnalysis(Analysis $analysis, array $options = array() $violations = $analysis->getViolations(); if ($violations) { foreach ($violations as $violation) { - /** + /* * @var $violation \SensioLabs\Insight\Sdk\Model\Violation */ $filename = $violation->getResource(); diff --git a/Cli/Descriptor/TextDescriptor.php b/Cli/Descriptor/TextDescriptor.php index ee13557..ff22b82 100644 --- a/Cli/Descriptor/TextDescriptor.php +++ b/Cli/Descriptor/TextDescriptor.php @@ -62,7 +62,7 @@ protected function describeAnalysis(Analysis $analysis, array $options = array() $template = <<{{ resource }}:{{ line }} Category: {{ category }} Severity: {{ severity }} -Title: {{ title }} +Title: {{ title }}{{ ignored }} Message: {{ message }} EOL; @@ -74,6 +74,7 @@ protected function describeAnalysis(Analysis $analysis, array $options = array() '{{ severity }}' => $violation->getSeverity(), '{{ title }}' => $violation->getTitle(), '{{ message }}' => $violation->getMessage(), + '{{ ignored }}' => $violation->isIgnored() ? ' (ignored)' : null, ))); } } diff --git a/Cli/Helper/DescriptorHelper.php b/Cli/Helper/DescriptorHelper.php index ad0048e..4b6c8ff 100644 --- a/Cli/Helper/DescriptorHelper.php +++ b/Cli/Helper/DescriptorHelper.php @@ -34,14 +34,15 @@ public function __construct(Serializer $serializer) ; } - public function describe(OutputInterface $output, $object, $format = null, $raw = false, $namespace = null) + public function describe(OutputInterface $output, $object, $format = null, $showIgnoredViolation = false) { $options = array( - 'raw_text' => $raw, + 'raw_text' => false, 'format' => $format ?: 'txt', 'output' => $output, + 'show_ignored_violations' => $showIgnoredViolation, ); - $options['type'] = !$raw && 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; + $options['type'] = 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW; if (!isset($this->descriptors[$options['format']])) { throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format'])); diff --git a/Sdk/Model/Analysis.php b/Sdk/Model/Analysis.php index a5a4c67..9bc5d0e 100644 --- a/Sdk/Model/Analysis.php +++ b/Sdk/Model/Analysis.php @@ -17,8 +17,8 @@ class Analysis { - const STATUS_ORDERED = 'ordered'; - const STATUS_RUNNING = 'running'; + const STATUS_ORDERED = 'ordered'; + const STATUS_RUNNING = 'running'; const STATUS_MEASURED = 'measured'; const STATUS_ANALYZED = 'analyzed'; const STATUS_FINISHED = 'finished'; diff --git a/Sdk/Model/Project.php b/Sdk/Model/Project.php index 2fcc0e7..a52c649 100644 --- a/Sdk/Model/Project.php +++ b/Sdk/Model/Project.php @@ -96,11 +96,11 @@ class Project public function toArray() { return array( - 'name' => $this->name, - 'public' => !$this->private, - 'description' => $this->description, + 'name' => $this->name, + 'public' => !$this->private, + 'description' => $this->description, 'repositoryUrl' => $this->repositoryUrl, - 'type' => $this->type, + 'type' => $this->type, 'configuration' => $this->configuration, ); } diff --git a/Sdk/Model/Violation.php b/Sdk/Model/Violation.php index 28f681b..6c63f51 100644 --- a/Sdk/Model/Violation.php +++ b/Sdk/Model/Violation.php @@ -40,6 +40,12 @@ class Violation */ private $category; + /** + * @Type("boolean") + * @XmlAttribute + */ + private $ignored; + /** * @return string */ @@ -87,4 +93,12 @@ public function getCategory() { return $this->category; } + + /** + * @return bool + */ + public function isIgnored() + { + return $this->ignored; + } } diff --git a/Sdk/Model/Violations.php b/Sdk/Model/Violations.php index 5be9e5e..1354c36 100644 --- a/Sdk/Model/Violations.php +++ b/Sdk/Model/Violations.php @@ -39,4 +39,16 @@ public function getViolations() { return $this->violations; } + + /** + * @param callable $callback + */ + public function filter($callback) + { + if (!is_callable($callback)) { + throw new \InvalidArgumentException('The callback is not callable.'); + } + + $this->violations = array_filter($this->violations, $callback); + } } diff --git a/Sdk/Tests/ApiTest.php b/Sdk/Tests/ApiTest.php index 9ed7608..f382678 100644 --- a/Sdk/Tests/ApiTest.php +++ b/Sdk/Tests/ApiTest.php @@ -231,5 +231,4 @@ private function createResponse($fixture, $statusCode = 200) { return new Response($statusCode, null, file_get_contents(sprintf('%s/fixtures/%s.xml', __DIR__, $fixture))); } - } diff --git a/Sdk/Tests/ParserTest.php b/Sdk/Tests/ParserTest.php index 41ed14a..93c4ffa 100644 --- a/Sdk/Tests/ParserTest.php +++ b/Sdk/Tests/ParserTest.php @@ -61,7 +61,7 @@ public function testParseErrors() ); $this->assertInstanceOf('SensioLabs\Insight\Sdk\Model\Error', $error); - $this->assertSame($expectedFields , $error->getEntityBodyParameters()); + $this->assertSame($expectedFields, $error->getEntityBodyParameters()); } public function tearDown()