@@ -321,7 +321,7 @@ public function getDefaults()
321321
322322 $ reportWidth = PHP_CodeSniffer::getConfigData ('report_width ' );
323323 if ($ reportWidth !== null ) {
324- $ defaults ['reportWidth ' ] = $ reportWidth ;
324+ $ defaults ['reportWidth ' ] = $ this -> _validateReportWidth ( $ reportWidth) ;
325325 } else {
326326 // Use function defaults.
327327 $ defaults ['reportWidth ' ] = null ;
@@ -374,18 +374,6 @@ public function getCommandLineValues()
374374 array_shift ($ args );
375375
376376 $ this ->setCommandLineValues ($ args );
377-
378- // Support auto temrinal width.
379- if (isset ($ this ->values ['reportWidth ' ]) === true ) {
380- if ($ this ->values ['reportWidth ' ] === 'auto '
381- && preg_match ('|\d+ (\d+)| ' , shell_exec ('stty size 2>&1 ' ), $ matches ) === 1
382- ) {
383- $ this ->values ['reportWidth ' ] = (int ) $ matches [1 ];
384- } else {
385- $ this ->values ['reportWidth ' ] = (int ) $ this ->values ['reportWidth ' ];
386- }
387- }
388-
389377 return $ this ->values ;
390378
391379 }//end getCommandLineValues()
@@ -644,7 +632,7 @@ public function processLongArgument($arg, $pos)
644632 }
645633 }
646634 } else if (substr ($ arg , 0 , 13 ) === 'report-width= ' ) {
647- $ this ->values ['reportWidth ' ] = substr ($ arg , 13 );
635+ $ this ->values ['reportWidth ' ] = $ this -> _validateReportWidth ( substr ($ arg , 13 ) );
648636 } else if (substr ($ arg , 0 , 7 ) === 'report= '
649637 || substr ($ arg , 0 , 7 ) === 'report- '
650638 ) {
@@ -1267,4 +1255,25 @@ public function printInstalledStandards()
12671255 }//end printInstalledStandards()
12681256
12691257
1258+ /**
1259+ * Set report width based on terminal width.
1260+ *
1261+ * @param int $width The width of the report. If "auto" then will
1262+ * be replaced by the terminal width.
1263+ *
1264+ * @return void
1265+ */
1266+ private function _validateReportWidth ($ width )
1267+ {
1268+ if ($ width === 'auto '
1269+ && preg_match ('|\d+ (\d+)| ' , shell_exec ('stty size 2>&1 ' ), $ matches ) === 1
1270+ ) {
1271+ return (int ) $ matches [1 ];
1272+ }
1273+
1274+ return (int ) $ width ;
1275+
1276+ }//end _validateReportWidth()
1277+
1278+
12701279}//end class
0 commit comments