diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index 9be2ebd7..8d882804 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -42,12 +42,6 @@ parameters: count: 1 path: ../src/Rule/Rule.php - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 1 - path: ../src/RuleSet/DeclarationBlock.php - - message: '#^Parameters should have "string" types as the only types passed to this method$#' identifier: typePerfect.narrowPublicClassMethodParamType diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index e4125797..5280e5a1 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -41,17 +41,25 @@ public static function parse(ParserState $parserState, ?CSSList $list = null): ? $result = new DeclarationBlock($parserState->currentLine()); try { $selectorParts = []; + $stringWrapperCharacter = null; do { $selectorParts[] = $parserState->consume(1) . $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $comments); - if (\in_array($parserState->peek(), ['\'', '"'], true) && \substr(\end($selectorParts), -1) != '\\') { - if (!isset($stringWrapperCharacter)) { - $stringWrapperCharacter = $parserState->peek(); - } elseif ($stringWrapperCharacter === $parserState->peek()) { - unset($stringWrapperCharacter); - } + $nextCharacter = $parserState->peek(); + switch ($nextCharacter) { + case '\'': + // The fallthrough is intentional. + case '"': + if (!\is_string($stringWrapperCharacter)) { + $stringWrapperCharacter = $nextCharacter; + } elseif ($stringWrapperCharacter === $nextCharacter) { + if (\substr(\end($selectorParts), -1) !== '\\') { + $stringWrapperCharacter = null; + } + } + break; } - } while (!\in_array($parserState->peek(), ['{', '}'], true) || isset($stringWrapperCharacter)); + } while (!\in_array($nextCharacter, ['{', '}'], true) || \is_string($stringWrapperCharacter)); $result->setSelectors(\implode('', $selectorParts), $list); if ($parserState->comes('{')) { $parserState->consume(1);