Skip to content

Commit 35fc9b9

Browse files
committed
Merge branch 'feature/3760-php-8.1-config-passing-null-to-non-nullable' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents e8e1d25 + 8bdbd56 commit 35fc9b9

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/Config.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ class Config
8989
*/
9090
const STABILITY = 'stable';
9191

92+
/**
93+
* Default report width when no report width is provided and 'auto' does not yield a valid width.
94+
*
95+
* @var int
96+
*/
97+
const DEFAULT_REPORT_WIDTH = 80;
98+
9299
/**
93100
* An array of settings that PHPCS and PHPCBF accept.
94101
*
@@ -223,13 +230,20 @@ public function __set($name, $value)
223230
switch ($name) {
224231
case 'reportWidth' :
225232
// Support auto terminal width.
226-
if ($value === 'auto'
227-
&& function_exists('shell_exec') === true
228-
&& preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1
229-
) {
230-
$value = (int) $matches[1];
231-
} else {
233+
if ($value === 'auto' && function_exists('shell_exec') === true) {
234+
$dimensions = shell_exec('stty size 2>&1');
235+
if (is_string($dimensions) === true && preg_match('|\d+ (\d+)|', $dimensions, $matches) === 1) {
236+
$value = (int) $matches[1];
237+
break;
238+
}
239+
}
240+
241+
if (is_int($value) === true) {
242+
$value = abs($value);
243+
} else if (is_string($value) === true && preg_match('`^\d+$`', $value) === 1) {
232244
$value = (int) $value;
245+
} else {
246+
$value = self::DEFAULT_REPORT_WIDTH;
233247
}
234248
break;
235249
case 'standards' :

0 commit comments

Comments
 (0)