Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/en/plugins/php_code_sniffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 48 additions & 4 deletions src/PHPCensor/Plugin/PhpCodeSniffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -118,6 +132,18 @@ public function __construct(Builder $builder, Build $build, array $options = [])
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'];
}
}

/**
Expand All @@ -143,21 +169,24 @@ public static function canExecute($stage, Builder $builder, Build $build)
*/
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,
$suffixes,
$ignore,
$this->tab_width,
$this->encoding,
$this->builder->buildPath . $this->path
$this->builder->buildPath . $this->path,
$severity,
$errorSeverity,
$warningSeverity
);

$output = $this->builder->getLastOutput();
Expand Down Expand Up @@ -202,7 +231,22 @@ protected function getFlags()
$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];
}

/**
Expand Down