Skip to content

Commit

Permalink
Merge branch 'feature/3760-php-8.1-config-passing-null-to-non-nullabl…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed May 7, 2023
2 parents e8e1d25 + 8bdbd56 commit 35fc9b9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ class Config
*/
const STABILITY = 'stable';

/**
* Default report width when no report width is provided and 'auto' does not yield a valid width.
*
* @var int
*/
const DEFAULT_REPORT_WIDTH = 80;

/**
* An array of settings that PHPCS and PHPCBF accept.
*
Expand Down Expand Up @@ -223,13 +230,20 @@ public function __set($name, $value)
switch ($name) {
case 'reportWidth' :
// Support auto terminal width.
if ($value === 'auto'
&& function_exists('shell_exec') === true
&& preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1
) {
$value = (int) $matches[1];
} else {
if ($value === 'auto' && function_exists('shell_exec') === true) {
$dimensions = shell_exec('stty size 2>&1');
if (is_string($dimensions) === true && preg_match('|\d+ (\d+)|', $dimensions, $matches) === 1) {
$value = (int) $matches[1];
break;
}
}

if (is_int($value) === true) {
$value = abs($value);
} else if (is_string($value) === true && preg_match('`^\d+$`', $value) === 1) {
$value = (int) $value;
} else {
$value = self::DEFAULT_REPORT_WIDTH;
}
break;
case 'standards' :
Expand Down

0 comments on commit 35fc9b9

Please sign in to comment.