diff --git a/config/php-cs-fixer.php b/config/php-cs-fixer.php index bc449156..26dfd245 100644 --- a/config/php-cs-fixer.php +++ b/config/php-cs-fixer.php @@ -22,6 +22,9 @@ // overwrite the PER2 defaults to restore compatibility with PHP 7.x 'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match']], + // for `in_array` & friends + 'strict_param' => true, + 'php_unit_construct' => true, 'php_unit_dedicate_assert' => ['target' => 'newest'], 'php_unit_expectation' => ['target' => 'newest'], diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index 02c47719..b221acf0 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -372,7 +372,7 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a while (!$this->isEnd()) { $char = $this->consume(1); - if (in_array($char, $aEnd)) { + if (in_array($char, $aEnd, true)) { if ($bIncludeEnd) { $out .= $char; } elseif (!$consumeEnd) { @@ -386,7 +386,7 @@ public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, a } } - if (in_array(self::EOF, $aEnd)) { + if (in_array(self::EOF, $aEnd, true)) { return $out; } diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 44b1bb6a..73796fd0 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -60,14 +60,14 @@ public static function parse(ParserState $oParserState, $oList = null) do { $aSelectorParts[] = $oParserState->consume(1) . $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments); - if (in_array($oParserState->peek(), ['\'', '"']) && substr(end($aSelectorParts), -1) != "\\") { + if (in_array($oParserState->peek(), ['\'', '"'], true) && substr(end($aSelectorParts), -1) != "\\") { if ($sStringWrapperChar === false) { $sStringWrapperChar = $oParserState->peek(); } elseif ($sStringWrapperChar == $oParserState->peek()) { $sStringWrapperChar = false; } } - } while (!in_array($oParserState->peek(), ['{', '}']) || $sStringWrapperChar !== false); + } while (!in_array($oParserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false); $oResult->setSelectors(implode('', $aSelectorParts), $oList); if ($oParserState->comes('{')) { $oParserState->consume(1); @@ -229,7 +229,7 @@ public function expandBorderShorthand(): void } elseif ($mValue instanceof Color) { $sNewRuleName = $sBorderRule . "-color"; } else { - if (in_array($mValue, $aBorderSizes)) { + if (in_array($mValue, $aBorderSizes, true)) { $sNewRuleName = $sBorderRule . "-width"; } else { $sNewRuleName = $sBorderRule . "-style"; @@ -338,20 +338,19 @@ public function expandFontShorthand(): void if (!$mValue instanceof Value) { $mValue = mb_strtolower($mValue); } - if (in_array($mValue, ['normal', 'inherit'])) { + if (in_array($mValue, ['normal', 'inherit'], true)) { foreach (['font-style', 'font-weight', 'font-variant'] as $sProperty) { if (!isset($aFontProperties[$sProperty])) { $aFontProperties[$sProperty] = $mValue; } } - } elseif (in_array($mValue, ['italic', 'oblique'])) { + } elseif (in_array($mValue, ['italic', 'oblique'], true)) { $aFontProperties['font-style'] = $mValue; } elseif ($mValue == 'small-caps') { $aFontProperties['font-variant'] = $mValue; } elseif ( - in_array($mValue, ['bold', 'bolder', 'lighter']) - || ($mValue instanceof Size - && in_array($mValue->getSize(), range(100, 900, 100))) + in_array($mValue, ['bold', 'bolder', 'lighter'], true) + || ($mValue instanceof Size && in_array($mValue->getSize(), range(100.0, 900.0, 100.0), true)) ) { $aFontProperties['font-weight'] = $mValue; } elseif ($mValue instanceof RuleValueList && $mValue->getListSeparator() == '/') { @@ -425,12 +424,12 @@ public function expandBackgroundShorthand(): void $aBgProperties['background-image'] = $mValue; } elseif ($mValue instanceof Color) { $aBgProperties['background-color'] = $mValue; - } elseif (in_array($mValue, ['scroll', 'fixed'])) { + } elseif (in_array($mValue, ['scroll', 'fixed'], true)) { $aBgProperties['background-attachment'] = $mValue; - } elseif (in_array($mValue, ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'])) { + } elseif (in_array($mValue, ['repeat', 'no-repeat', 'repeat-x', 'repeat-y'], true)) { $aBgProperties['background-repeat'] = $mValue; } elseif ( - in_array($mValue, ['left', 'center', 'right', 'top', 'bottom']) + in_array($mValue, ['left', 'center', 'right', 'top', 'bottom'], true) || $mValue instanceof Size ) { if ($iNumBgPos == 0) { @@ -516,9 +515,9 @@ public function expandListStyleShorthand(): void } if ($mValue instanceof Url) { $aListProperties['list-style-image'] = $mValue; - } elseif (in_array($mValue, $aListStyleTypes)) { + } elseif (in_array($mValue, $aListStyleTypes, true)) { $aListProperties['list-style-types'] = $mValue; - } elseif (in_array($mValue, $aListStylePositions)) { + } elseif (in_array($mValue, $aListStylePositions, true)) { $aListProperties['list-style-position'] = $mValue; } } diff --git a/src/Value/CalcFunction.php b/src/Value/CalcFunction.php index 85f4085a..7487edf5 100644 --- a/src/Value/CalcFunction.php +++ b/src/Value/CalcFunction.php @@ -29,7 +29,7 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals if ($oParserState->peek() != '(') { // Found ; or end of line before an opening bracket throw new UnexpectedTokenException('(', $oParserState->peek(), 'literal', $oParserState->currentLine()); - } elseif (!in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'])) { + } elseif (!in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'], true)) { // Found invalid calc definition. Example calc (... throw new UnexpectedTokenException('calc', $sFunction, 'literal', $oParserState->currentLine()); } @@ -60,7 +60,7 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals $oCalcList->addListComponent($oVal); $iLastComponentType = CalcFunction::T_OPERAND; } else { - if (in_array($oParserState->peek(), $aOperators)) { + if (in_array($oParserState->peek(), $aOperators, true)) { if (($oParserState->comes('-') || $oParserState->comes('+'))) { if ( $oParserState->peek(1, -1) != ' '