Skip to content

Commit d6821b9

Browse files
authored
[TASK] Always use the strict version of in_array & friends (MyIntervals#584)
1 parent 8dc723d commit d6821b9

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

config/php-cs-fixer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
// overwrite the PER2 defaults to restore compatibility with PHP 7.x
2323
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match']],
2424

25+
// for `in_array` & friends
26+
'strict_param' => true,
27+
2528
'php_unit_construct' => true,
2629
'php_unit_dedicate_assert' => ['target' => 'newest'],
2730
'php_unit_expectation' => ['target' => 'newest'],

src/Parsing/ParserState.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
372372

373373
while (!$this->isEnd()) {
374374
$char = $this->consume(1);
375-
if (in_array($char, $aEnd)) {
375+
if (in_array($char, $aEnd, true)) {
376376
if ($bIncludeEnd) {
377377
$out .= $char;
378378
} elseif (!$consumeEnd) {
@@ -386,7 +386,7 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a
386386
}
387387
}
388388

389-
if (in_array(self::EOF, $aEnd)) {
389+
if (in_array(self::EOF, $aEnd, true)) {
390390
return $out;
391391
}
392392

src/RuleSet/DeclarationBlock.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public static function parse(ParserState $oParserState, $oList = null)
6060
do {
6161
$aSelectorParts[] = $oParserState->consume(1)
6262
. $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
63-
if (in_array($oParserState->peek(), ['\'', '"']) && substr(end($aSelectorParts), -1) != "\\") {
63+
if (in_array($oParserState->peek(), ['\'', '"'], true) && substr(end($aSelectorParts), -1) != "\\") {
6464
if ($sStringWrapperChar === false) {
6565
$sStringWrapperChar = $oParserState->peek();
6666
} elseif ($sStringWrapperChar == $oParserState->peek()) {
6767
$sStringWrapperChar = false;
6868
}
6969
}
70-
} while (!in_array($oParserState->peek(), ['{', '}']) || $sStringWrapperChar !== false);
70+
} while (!in_array($oParserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false);
7171
$oResult->setSelectors(implode('', $aSelectorParts), $oList);
7272
if ($oParserState->comes('{')) {
7373
$oParserState->consume(1);
@@ -229,7 +229,7 @@ public function expandBorderShorthand(): void
229229
} elseif ($mValue instanceof Color) {
230230
$sNewRuleName = $sBorderRule . "-color";
231231
} else {
232-
if (in_array($mValue, $aBorderSizes)) {
232+
if (in_array($mValue, $aBorderSizes, true)) {
233233
$sNewRuleName = $sBorderRule . "-width";
234234
} else {
235235
$sNewRuleName = $sBorderRule . "-style";
@@ -338,20 +338,19 @@ public function expandFontShorthand(): void
338338
if (!$mValue instanceof Value) {
339339
$mValue = mb_strtolower($mValue);
340340
}
341-
if (in_array($mValue, ['normal', 'inherit'])) {
341+
if (in_array($mValue, ['normal', 'inherit'], true)) {
342342
foreach (['font-style', 'font-weight', 'font-variant'] as $sProperty) {
343343
if (!isset($aFontProperties[$sProperty])) {
344344
$aFontProperties[$sProperty] = $mValue;
345345
}
346346
}
347-
} elseif (in_array($mValue, ['italic', 'oblique'])) {
347+
} elseif (in_array($mValue, ['italic', 'oblique'], true)) {
348348
$aFontProperties['font-style'] = $mValue;
349349
} elseif ($mValue == 'small-caps') {
350350
$aFontProperties['font-variant'] = $mValue;
351351
} elseif (
352-
in_array($mValue, ['bold', 'bolder', 'lighter'])
353-
|| ($mValue instanceof Size
354-
&& in_array($mValue->getSize(), range(100, 900, 100)))
352+
in_array($mValue, ['bold', 'bolder', 'lighter'], true)
353+
|| ($mValue instanceof Size && in_array($mValue->getSize(), range(100.0, 900.0, 100.0), true))
355354
) {
356355
$aFontProperties['font-weight'] = $mValue;
357356
} elseif ($mValue instanceof RuleValueList && $mValue->getListSeparator() == '/') {
@@ -425,12 +424,12 @@ public function expandBackgroundShorthand(): void
425424
$aBgProperties['background-image'] = $mValue;
426425
} elseif ($mValue instanceof Color) {
427426
$aBgProperties['background-color'] = $mValue;
428-
} elseif (in_array($mValue, ['scroll', 'fixed'])) {
427+
} elseif (in_array($mValue, ['scroll', 'fixed'], true)) {
429428
$aBgProperties['background-attachment'] = $mValue;
430-
} elseif (in_array($mValue, ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'])) {
429+
} elseif (in_array($mValue, ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'], true)) {
431430
$aBgProperties['background-repeat'] = $mValue;
432431
} elseif (
433-
in_array($mValue, ['left', 'center', 'right', 'top', 'bottom'])
432+
in_array($mValue, ['left', 'center', 'right', 'top', 'bottom'], true)
434433
|| $mValue instanceof Size
435434
) {
436435
if ($iNumBgPos == 0) {
@@ -516,9 +515,9 @@ public function expandListStyleShorthand(): void
516515
}
517516
if ($mValue instanceof Url) {
518517
$aListProperties['list-style-image'] = $mValue;
519-
} elseif (in_array($mValue, $aListStyleTypes)) {
518+
} elseif (in_array($mValue, $aListStyleTypes, true)) {
520519
$aListProperties['list-style-types'] = $mValue;
521-
} elseif (in_array($mValue, $aListStylePositions)) {
520+
} elseif (in_array($mValue, $aListStylePositions, true)) {
522521
$aListProperties['list-style-position'] = $mValue;
523522
}
524523
}

src/Value/CalcFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
2929
if ($oParserState->peek() != '(') {
3030
// Found ; or end of line before an opening bracket
3131
throw new UnexpectedTokenException('(', $oParserState->peek(), 'literal', $oParserState->currentLine());
32-
} elseif (!in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'])) {
32+
} elseif (!in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'], true)) {
3333
// Found invalid calc definition. Example calc (...
3434
throw new UnexpectedTokenException('calc', $sFunction, 'literal', $oParserState->currentLine());
3535
}
@@ -60,7 +60,7 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals
6060
$oCalcList->addListComponent($oVal);
6161
$iLastComponentType = CalcFunction::T_OPERAND;
6262
} else {
63-
if (in_array($oParserState->peek(), $aOperators)) {
63+
if (in_array($oParserState->peek(), $aOperators, true)) {
6464
if (($oParserState->comes('-') || $oParserState->comes('+'))) {
6565
if (
6666
$oParserState->peek(1, -1) != ' '

0 commit comments

Comments
 (0)