diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index 1267af29..6f31def8 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -167,9 +167,12 @@ private static function parseAtRule(ParserState $oParserState) $sMediaQuery = null; if (!$oParserState->comes(';')) { $sMediaQuery = \trim($oParserState->consumeUntil([';', ParserState::EOF])); + if ($sMediaQuery === '') { + $sMediaQuery = null; + } } $oParserState->consumeUntil([';', ParserState::EOF], true, true); - return new Import($oLocation, $sMediaQuery ?: null, $iIdentifierLineNum); + return new Import($oLocation, $sMediaQuery, $iIdentifierLineNum); } elseif ($sIdentifier === 'charset') { $oCharsetString = CSSString::parse($oParserState); $oParserState->consumeWhiteSpace(); @@ -240,9 +243,8 @@ private static function parseAtRule(ParserState $oParserState) * We need to check for these versions too. * * @param string $sIdentifier - * @param string $sMatch */ - private static function identifierIs($sIdentifier, $sMatch): bool + private static function identifierIs($sIdentifier, string $sMatch): bool { return (\strcasecmp($sIdentifier, $sMatch) === 0) ?: \preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1; diff --git a/src/OutputFormat.php b/src/OutputFormat.php index 2b5607db..3f126346 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -223,14 +223,13 @@ public function set($aNames, $mValue) } /** - * @param string $sMethodName * @param array $aArguments * * @return mixed * * @throws \Exception */ - public function __call($sMethodName, array $aArguments) + public function __call(string $sMethodName, array $aArguments) { if (\strpos($sMethodName, 'set') === 0) { return $this->set(\substr($sMethodName, 3), $aArguments[0]); @@ -303,17 +302,15 @@ public function level() /** * Creates an instance of this class without any particular formatting settings. */ - public static function create(): OutputFormat + public static function create(): self { return new OutputFormat(); } /** * Creates an instance of this class with a preset for compact formatting. - * - * @return self */ - public static function createCompact() + public static function createCompact(): self { $format = self::create(); $format->set('Space*Rules', '') @@ -327,10 +324,8 @@ public static function createCompact() /** * Creates an instance of this class with a preset for pretty formatting. - * - * @return self */ - public static function createPretty() + public static function createPretty(): self { $format = self::create(); $format->set('Space*Rules', "\n") diff --git a/src/OutputFormatter.php b/src/OutputFormatter.php index 4349f664..6e68037f 100644 --- a/src/OutputFormatter.php +++ b/src/OutputFormatter.php @@ -132,11 +132,10 @@ public function safely($cCode) /** * Clone of the `implode` function, but calls `render` with the current output format instead of `__toString()`. * - * @param string $sSeparator * @param array $aValues * @param bool $bIncreaseLevel */ - public function implode($sSeparator, array $aValues, $bIncreaseLevel = false): string + public function implode(string $sSeparator, array $aValues, $bIncreaseLevel = false): string { $sResult = ''; $oFormat = $this->oFormat; diff --git a/src/Parsing/Anchor.php b/src/Parsing/Anchor.php index 1a1d42ae..545cb035 100644 --- a/src/Parsing/Anchor.php +++ b/src/Parsing/Anchor.php @@ -15,13 +15,12 @@ class Anchor private $iPosition; /** - * @var \Sabberworm\CSS\Parsing\ParserState + * @var ParserState */ private $oParserState; /** * @param int $iPosition - * @param \Sabberworm\CSS\Parsing\ParserState $oParserState */ public function __construct($iPosition, ParserState $oParserState) { diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index fa146d7e..22152fbd 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -362,12 +362,10 @@ public function isEnd(): bool * @param string $consumeEnd * @param array $comments * - * @return string - * * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = []) + public function consumeUntil($aEnd, $bIncludeEnd = false, $consumeEnd = false, array &$comments = []): string { $aEnd = \is_array($aEnd) ? $aEnd : [$aEnd]; $out = ''; diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index c2fd6e30..e53abd52 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -82,7 +82,7 @@ public static function parseRuleSet(ParserState $oParserState, RuleSet $oRuleSet } else { $oRule = Rule::parse($oParserState); } - if ($oRule) { + if ($oRule instanceof Rule) { $oRuleSet->addRule($oRule); } } diff --git a/src/Settings.php b/src/Settings.php index b5934a05..17e5fa00 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -56,9 +56,9 @@ public static function create(): Settings * * @param bool $bMultibyteSupport * - * @return self fluent interface + * @return $this fluent interface */ - public function withMultibyteSupport($bMultibyteSupport = true) + public function withMultibyteSupport($bMultibyteSupport = true): self { $this->bMultibyteSupport = $bMultibyteSupport; return $this; @@ -69,9 +69,9 @@ public function withMultibyteSupport($bMultibyteSupport = true) * * @param string $sDefaultCharset * - * @return self fluent interface + * @return $this fluent interface */ - public function withDefaultCharset($sDefaultCharset) + public function withDefaultCharset($sDefaultCharset): self { $this->sDefaultCharset = $sDefaultCharset; return $this; @@ -82,9 +82,9 @@ public function withDefaultCharset($sDefaultCharset) * * @param bool $bLenientParsing * - * @return self fluent interface + * @return $this fluent interface */ - public function withLenientParsing($bLenientParsing = true) + public function withLenientParsing($bLenientParsing = true): self { $this->bLenientParsing = $bLenientParsing; return $this; @@ -93,9 +93,9 @@ public function withLenientParsing($bLenientParsing = true) /** * Configures the parser to choke on invalid rules. * - * @return self fluent interface + * @return $this fluent interface */ - public function beStrict() + public function beStrict(): self { return $this->withLenientParsing(false); } diff --git a/src/Value/CSSFunction.php b/src/Value/CSSFunction.php index 5902cf77..82b21e8a 100644 --- a/src/Value/CSSFunction.php +++ b/src/Value/CSSFunction.php @@ -103,10 +103,7 @@ public function __toString(): string return $this->render(new OutputFormat()); } - /** - * @return string - */ - public function render(OutputFormat $oOutputFormat) + public function render(OutputFormat $oOutputFormat): string { $aArguments = parent::render($oOutputFormat); return "{$this->sName}({$aArguments})"; diff --git a/src/Value/CSSString.php b/src/Value/CSSString.php index 3385f48c..f212bdd8 100644 --- a/src/Value/CSSString.php +++ b/src/Value/CSSString.php @@ -53,7 +53,7 @@ public static function parse(ParserState $oParserState): CSSString $sContent = null; if ($sQuote === null) { // Unquoted strings end in whitespace or with braces, brackets, parentheses - while (!\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek())) { + while (\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek()) !== 1) { $sResult .= $oParserState->parseCharacter(false); } } else { diff --git a/src/Value/Color.php b/src/Value/Color.php index 706d1d1f..55a6ce3d 100644 --- a/src/Value/Color.php +++ b/src/Value/Color.php @@ -103,15 +103,9 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals } /** - * @param float $fVal - * @param float $fFromMin - * @param float $fFromMax - * @param float $fToMin - * @param float $fToMax - * * @return float */ - private static function mapRange($fVal, $fFromMin, $fFromMax, $fToMin, $fToMax) + private static function mapRange(float $fVal, float $fFromMin, float $fFromMax, float $fToMin, float $fToMax) { $fFromRange = $fFromMax - $fFromMin; $fToRange = $fToMax - $fToMin; @@ -151,10 +145,7 @@ public function __toString(): string return $this->render(new OutputFormat()); } - /** - * @return string - */ - public function render(OutputFormat $oOutputFormat) + public function render(OutputFormat $oOutputFormat): string { // Shorthand RGB color values if ($oOutputFormat->getRGBHashNotation() && \implode('', \array_keys($this->aComponents)) === 'rgb') {