From 97b2e34ef2ab97ed1831cfbdee42fc47937adaa3 Mon Sep 17 00:00:00 2001 From: Valeriy Tropin Date: Fri, 24 Mar 2017 20:03:08 +0200 Subject: [PATCH 1/2] - extend phpcs options --- src/PHPCensor/Plugin/PhpCodeSniffer.php | 52 +++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/PHPCensor/Plugin/PhpCodeSniffer.php b/src/PHPCensor/Plugin/PhpCodeSniffer.php index 1c463029..fc152356 100644 --- a/src/PHPCensor/Plugin/PhpCodeSniffer.php +++ b/src/PHPCensor/Plugin/PhpCodeSniffer.php @@ -61,6 +61,20 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface */ protected $ignore; + /** + * @var int + */ + protected $severity = null; + /** + * @var null|int + */ + protected $error_severity = null; + + /** + * @var null|int + */ + protected $warning_severity = null; + /** * @return string */ @@ -118,6 +132,18 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface if (!empty($options['standard'])) { $this->standard = $options['standard']; } + + if (isset($options['severity']) && is_int($options['severity'])) { + $this->severity = $options['severity']; + } + + if (isset($options['error_severity']) && is_int($options['error_severity'])) { + $this->error_severity = $options['error_severity']; + } + + if (isset($options['warning_severity']) && is_int($options['warning_severity'])) { + $this->warning_severity = $options['warning_severity']; + } } /** @@ -143,13 +169,13 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface */ public function execute() { - list($ignore, $standard, $suffixes) = $this->getFlags(); + list($ignore, $standard, $suffixes, $severity, $errorSeverity, $warningSeverity) = $this->getFlags(); $phpcs = $this->builder->findBinary('phpcs'); $this->builder->logExecOutput(false); - $cmd = $phpcs . ' --report=json %s %s %s %s %s "%s"'; + $cmd = $phpcs . ' --report=json %s %s %s %s %s "%s" %s %s %s'; $this->builder->executeCommand( $cmd, $standard, @@ -157,7 +183,10 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface $ignore, $this->tab_width, $this->encoding, - $this->builder->buildPath . $this->path + $this->builder->buildPath . $this->path, + $severity, + $errorSeverity, + $warningSeverity ); $output = $this->builder->getLastOutput(); @@ -202,7 +231,22 @@ class PhpCodeSniffer extends Plugin implements ZeroConfigPluginInterface $suffixes = ' --extensions=' . implode(',', $this->suffixes); } - return [$ignore, $standard, $suffixes]; + $severity = ''; + if ($this->severity !== null) { + $severity = ' --severity=' . $this->severity; + } + + $errorSeverity = ''; + if ($this->error_severity !== null) { + $errorSeverity = ' --error-severity=' . $this->error_severity; + } + + $warningSeverity = ''; + if ($this->warning_severity !== null) { + $warningSeverity = ' --warning-severity=' . $this->warning_severity; + } + + return [$ignore, $standard, $suffixes, $severity, $errorSeverity, $warningSeverity]; } /** From 980a1e1614f194f11afc2988c2851d61a1333b2e Mon Sep 17 00:00:00 2001 From: Valeriy Tropin Date: Fri, 24 Mar 2017 22:00:14 +0200 Subject: [PATCH 2/2] - extend plugin options --- docs/en/plugins/php_code_sniffer.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/en/plugins/php_code_sniffer.md b/docs/en/plugins/php_code_sniffer.md index c3ff3632..98d000be 100644 --- a/docs/en/plugins/php_code_sniffer.md +++ b/docs/en/plugins/php_code_sniffer.md @@ -16,6 +16,9 @@ Configuration * **encoding** [string, optional] - The file encoding you wish to check for. * **path** [string, optional] - Path in which to run PHP Code Sniffer. * **ignore** [array, optional] - A list of files / paths to ignore, defaults to the build_settings ignore list. +* **severity** [int, optional] - Allows to set the minimum severity level +* **error_severity** [int, optional] - Allows to set the minimum errors severity level +* **warning_severity** [int, optional] - Allows to set the minimum warnings severity level ### Examples