Skip to content

Commit aab9cd6

Browse files
authored
Merge pull request #1035 from PHPCSStandards/phpcs-4.0/modernize/use-php-os-family
Modernize: use `PHP_OS_FAMILY` constant
2 parents 4f0b383 + 82dd0e1 commit aab9cd6

File tree

8 files changed

+10
-10
lines changed

8 files changed

+10
-10
lines changed

src/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
450450
}//end if
451451

452452
if (defined('STDIN') === false
453-
|| stripos(PHP_OS, 'WIN') === 0
453+
|| PHP_OS_FAMILY === 'Windows'
454454
) {
455455
return;
456456
}
@@ -1614,7 +1614,7 @@ public static function getExecutablePath($name)
16141614
return self::$executablePaths[$name];
16151615
}
16161616

1617-
if (stripos(PHP_OS, 'WIN') === 0) {
1617+
if (PHP_OS_FAMILY === 'Windows') {
16181618
$cmd = 'where '.escapeshellarg($name).' 2> nul';
16191619
} else {
16201620
$cmd = 'which '.escapeshellarg($name).' 2> /dev/null';

src/Fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ public function generateDiff($filePath=null, $colors=true)
284284
];
285285

286286
$options = null;
287-
if (stripos(PHP_OS, 'WIN') === 0) {
287+
if (PHP_OS_FAMILY === 'Windows') {
288288
$options = ['bypass_shell' => true];
289289
}
290290

src/Reports/Code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function generateFileReport($report, File $phpcsFile, $showSources=false,
230230
if (strpos($tokenContent, "\t") !== false) {
231231
$token = $tokens[$i];
232232
$token['content'] = $tokenContent;
233-
if (stripos(PHP_OS, 'WIN') === 0) {
233+
if (PHP_OS_FAMILY === 'Windows') {
234234
$tab = "\000";
235235
} else {
236236
$tab = "\033[30;1m»\033[0m";

src/Standards/Generic/Tests/Files/ExecutableFileUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class ExecutableFileUnitTest extends AbstractSniffTestCase
2828
protected function shouldSkipTest()
2929
{
3030
// Skip on Windows which doesn't have the concept of executable files.
31-
return (stripos(PHP_OS, 'WIN') === 0);
31+
return PHP_OS_FAMILY === 'Windows';
3232

3333
}//end shouldSkipTest()
3434

src/Tokenizers/PHP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ protected function tokenize($string)
528528
if (PHP_CODESNIFFER_VERBOSITY > 1) {
529529
StatusWriter::write('*** START PHP TOKENIZING ***', 1);
530530
$isWin = false;
531-
if (stripos(PHP_OS, 'WIN') === 0) {
531+
if (PHP_OS_FAMILY === 'Windows') {
532532
$isWin = true;
533533
}
534534
}

src/Util/Common.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public static function escapeshellcmd($cmd)
253253
{
254254
$cmd = escapeshellcmd($cmd);
255255

256-
if (stripos(PHP_OS, 'WIN') === 0) {
256+
if (PHP_OS_FAMILY === 'Windows') {
257257
// Spaces are not escaped by escapeshellcmd on Windows, but need to be
258258
// for the command to be able to execute.
259259
$cmd = preg_replace('`(?<!^) `', '^ ', $cmd);
@@ -278,7 +278,7 @@ public static function escapeshellcmd($cmd)
278278
*/
279279
public static function prepareForOutput($content, $exclude=[])
280280
{
281-
if (stripos(PHP_OS, 'WIN') === 0) {
281+
if (PHP_OS_FAMILY === 'Windows') {
282282
if (in_array("\r", $exclude, true) === false) {
283283
$content = str_replace("\r", '\r', $content);
284284
}

tests/Core/Ruleset/ExpandRulesetReferenceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static function dataUnresolvableReferenceThrowsException()
115115
];
116116

117117
// Add tests which are only relevant for case-sensitive OSes.
118-
if (stripos(PHP_OS, 'WIN') === false) {
118+
if (PHP_OS_FAMILY !== 'Windows') {
119119
$data['Referencing an existing sniff, but there is a case mismatch (OS-dependent) [1]'] = [
120120
'standard' => 'ExpandRulesetReferenceCaseMismatch1Test.xml',
121121
'replacement' => 'psr12.functions.nullabletypedeclaration',

tests/Core/Util/Common/EscapeshellcmdTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ final class EscapeshellcmdTest extends TestCase
3636
*/
3737
public function testEscapeshellcmd($command, $expected, $expectedWin=null)
3838
{
39-
if (stripos(PHP_OS, 'WIN') === 0 && empty($expectedWin) === false) {
39+
if (PHP_OS_FAMILY === 'Windows' && empty($expectedWin) === false) {
4040
$expected = $expectedWin;
4141
}
4242

0 commit comments

Comments
 (0)