Skip to content

Commit c280c14

Browse files
committed
Girlscouting: Use strict comparisons when using in_array()
Prevent quirks caused by type juggling when using the default of `$strict = false`. Ref: http://php.net/manual/en/function.in-array.php
1 parent 219d3da commit c280c14

20 files changed

+39
-39
lines changed

src/Files/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,9 @@ protected function addMessage($error, $message, $line, $column, $code, $data, $s
895895
// due to the use of the --sniffs command line argument.
896896
if ($includeAll === false
897897
&& ((empty($this->configCache['sniffs']) === false
898-
&& in_array(strtolower($listenerCode), $this->configCache['sniffs']) === false)
898+
&& in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899899
|| (empty($this->configCache['exclude']) === false
900-
&& in_array(strtolower($listenerCode), $this->configCache['exclude']) === true))
900+
&& in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
901901
) {
902902
return false;
903903
}
@@ -2346,7 +2346,7 @@ public function hasCondition($stackPtr, $types)
23462346
$conditions = $this->tokens[$stackPtr]['conditions'];
23472347

23482348
foreach ($types as $type) {
2349-
if (in_array($type, $conditions) === true) {
2349+
if (in_array($type, $conditions, true) === true) {
23502350
// We found a token with the required type.
23512351
return true;
23522352
}

src/Ruleset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public function processRuleset($rulesetPath, $depth=0)
410410
}
411411
} else if (empty($newSniffs) === false) {
412412
$newSniff = $newSniffs[0];
413-
if (in_array($newSniff, $ownSniffs) === false) {
413+
if (in_array($newSniff, $ownSniffs, true) === false) {
414414
// Including a sniff that hasn't been included higher up, but
415415
// only including a single message from it. So turn off all messages in
416416
// the sniff, except this one.
@@ -578,7 +578,7 @@ public function processRuleset($rulesetPath, $depth=0)
578578
// sniff list, but filter out any excluded sniffs.
579579
$files = [];
580580
foreach ($includedSniffs as $sniff) {
581-
if (in_array($sniff, $excludedSniffs) === true) {
581+
if (in_array($sniff, $excludedSniffs, true) === true) {
582582
continue;
583583
} else {
584584
$files[] = Util\Common::realpath($sniff);

src/Sniffs/AbstractPatternSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ final public function process(File $phpcsFile, $stackPtr)
195195

196196
$tokens = $phpcsFile->getTokens();
197197

198-
if (in_array($tokens[$stackPtr]['code'], $this->supplementaryTokens) === true) {
198+
if (in_array($tokens[$stackPtr]['code'], $this->supplementaryTokens, true) === true) {
199199
$this->processSupplementary($phpcsFile, $stackPtr);
200200
}
201201

src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function process(File $phpcsFile, $stackPtr)
153153
break;
154154
}
155155

156-
if (in_array($tokens[$end]['code'], $fixableScopeOpeners) === true
156+
if (in_array($tokens[$end]['code'], $fixableScopeOpeners, true) === true
157157
&& isset($tokens[$end]['scope_opener']) === false
158158
) {
159159
// The best way to fix nested inline scopes is middle-out.

src/Standards/Generic/Sniffs/PHP/ForbiddenFunctionsSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function process(File $phpcsFile, $stackPtr)
173173
// Remove the pattern delimiters and modifier.
174174
$pattern = substr($pattern, 1, -2);
175175
} else {
176-
if (in_array($function, $this->forbiddenFunctionNames) === false) {
176+
if (in_array($function, $this->forbiddenFunctionNames, true) === false) {
177177
return;
178178
}
179179
}//end if

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ public function process(File $phpcsFile, $stackPtr)
776776

777777
if ($checkToken !== null
778778
&& isset(Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true
779-
&& in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes) === false
779+
&& in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes, true) === false
780780
&& isset($tokens[$checkToken]['scope_opener']) === true
781781
) {
782782
$exact = true;
@@ -1133,7 +1133,7 @@ public function process(File $phpcsFile, $stackPtr)
11331133

11341134
$condition = $tokens[$tokens[$i]['scope_condition']]['code'];
11351135
if (isset(Tokens::$scopeOpeners[$condition]) === true
1136-
&& in_array($condition, $this->nonIndentingScopes) === false
1136+
&& in_array($condition, $this->nonIndentingScopes, true) === false
11371137
) {
11381138
if ($this->debug === true) {
11391139
$line = $tokens[$i]['line'];

src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function process(File $phpcsFile, $stackPtr)
161161
T_PROPERTY,
162162
];
163163

164-
if (in_array($tokens[$nextToken]['code'], $ignore) === true) {
164+
if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
165165
$phpcsFile->addError('Missing file doc comment', $stackPtr, 'Missing');
166166
$phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'no');
167167
return ($phpcsFile->numTokens + 1);

src/Standards/PSR2/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function processOpen(File $phpcsFile, $stackPtr)
7171
$blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar));
7272
$spaces = strlen($blankSpace);
7373

74-
if (in_array($tokens[($stackPtr - 2)]['code'], [T_ABSTRACT, T_FINAL]) === true
74+
if (in_array($tokens[($stackPtr - 2)]['code'], [T_ABSTRACT, T_FINAL], true) === true
7575
&& $spaces !== 1
7676
) {
7777
$prevContent = strtolower($tokens[($stackPtr - 2)]['content']);

src/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function process(File $phpcsFile, $stackPtr)
115115
// Remove the pattern delimiters and modifier.
116116
$pattern = substr($pattern, 1, -2);
117117
} else {
118-
if (in_array($style, $this->forbiddenStyleNames) === false) {
118+
if (in_array($style, $this->forbiddenStyleNames, true) === false) {
119119
return;
120120
}
121121
}//end if

src/Standards/Squiz/Sniffs/Commenting/FileCommentSniff.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function process(File $phpcsFile, $stackPtr)
9999
T_REQUIRE_ONCE,
100100
];
101101

102-
if (in_array($tokens[$nextToken]['code'], $ignore) === true) {
102+
if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
103103
$phpcsFile->addError('Missing file doc comment', $stackPtr, 'Missing');
104104
$phpcsFile->recordMetric($stackPtr, 'File has doc comment', 'no');
105105
return ($phpcsFile->numTokens + 1);
@@ -133,7 +133,7 @@ public function process(File $phpcsFile, $stackPtr)
133133
$name = $tokens[$tag]['content'];
134134
$isRequired = isset($required[$name]);
135135

136-
if ($isRequired === true && in_array($name, $foundTags) === true) {
136+
if ($isRequired === true && in_array($name, $foundTags, true) === true) {
137137
$error = 'Only one %s tag is allowed in a file comment';
138138
$data = [$name];
139139
$phpcsFile->addError($error, $tag, 'Duplicate'.ucfirst(substr($name, 1)).'Tag', $data);
@@ -183,7 +183,7 @@ public function process(File $phpcsFile, $stackPtr)
183183
// Check if the tags are in the correct position.
184184
$pos = 0;
185185
foreach ($required as $tag => $true) {
186-
if (in_array($tag, $foundTags) === false) {
186+
if (in_array($tag, $foundTags, true) === false) {
187187
$error = 'Missing %s tag in file comment';
188188
$data = [$tag];
189189
$phpcsFile->addError($error, $commentEnd, 'Missing'.ucfirst(substr($tag, 1)).'Tag', $data);

0 commit comments

Comments
 (0)