Skip to content

Commit

Permalink
QA: minor code simplification
Browse files Browse the repository at this point in the history
Replace a nested function call with a singular function call, which does the same.
  • Loading branch information
jrfnl committed Feb 6, 2022
1 parent 498a939 commit 6100f99
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
}//end if

if (defined('STDIN') === false
|| strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'
|| stripos(PHP_OS, 'WIN') === 0
) {
return;
}
Expand Down Expand Up @@ -1517,7 +1517,7 @@ public static function getExecutablePath($name)
return self::$executablePaths[$name];
}

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
$cmd = 'where '.escapeshellarg($name).' 2> nul';
} else {
$cmd = 'which '.escapeshellarg($name).' 2> /dev/null';
Expand Down
2 changes: 1 addition & 1 deletion src/Reports/Code.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
if (strpos($tokenContent, "\t") !== false) {
$token = $tokens[$i];
$token['content'] = $tokenContent;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
$tab = "\000";
} else {
$tab = "\033[30;1m»\033[0m";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function shouldSkipTest()
// PEAR doesn't preserve the executable flag, so skip
// tests when running in a PEAR install.
// Also skip on Windows which doesn't have the concept of executable files.
return ($GLOBALS['PHP_CODESNIFFER_PEAR'] || (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'));
return ($GLOBALS['PHP_CODESNIFFER_PEAR'] || stripos(PHP_OS, 'WIN') === 0);

}//end shouldSkipTest()

Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ protected function tokenize($string)
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "\t*** START PHP TOKENIZING ***".PHP_EOL;
$isWin = false;
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
$isWin = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Util/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static function escapeshellcmd($cmd)
{
$cmd = escapeshellcmd($cmd);

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
// Spaces are not escaped by escapeshellcmd on Windows, but need to be
// for the command to be able to execute.
$cmd = preg_replace('`(?<!^) `', '^ ', $cmd);
Expand All @@ -275,7 +275,7 @@ public static function escapeshellcmd($cmd)
*/
public static function prepareForOutput($content, $exclude=[])
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
if (stripos(PHP_OS, 'WIN') === 0) {
if (in_array("\r", $exclude, true) === false) {
$content = str_replace("\r", '\r', $content);
}
Expand Down

0 comments on commit 6100f99

Please sign in to comment.