From eb96b36005e62cfb4371612714c6669bf0c81b0d Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 16 Mar 2025 11:09:27 +0100 Subject: [PATCH] [TASK] Add native type declarations for `Import` Part of #811 --- CHANGELOG.md | 2 +- config/phpstan-baseline.neon | 6 ------ src/Property/Import.php | 27 +++++++++------------------ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73fed056..83e57bbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,7 @@ Please also have a look at our - Use more native type declarations and strict mode (#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958, #964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145, - #1162, #1163, #1166) + #1162, #1163, #1166, #1172) - Add visibility to all class/interface constants (#469) ### Deprecated diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index bc85f357..81275efa 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -72,12 +72,6 @@ parameters: count: 1 path: ../src/Property/Charset.php - - - message: '#^Only booleans are allowed in an if condition, string given\.$#' - identifier: if.condNotBoolean - count: 1 - path: ../src/Property/Import.php - - message: '#^Only booleans are allowed in an if condition, Sabberworm\\CSS\\Value\\RuleValueList\|string\|null given\.$#' identifier: if.condNotBoolean diff --git a/src/Property/Import.php b/src/Property/Import.php index 19bee125..615b612a 100644 --- a/src/Property/Import.php +++ b/src/Property/Import.php @@ -19,7 +19,7 @@ class Import implements AtRule private $location; /** - * @var string + * @var string|null */ private $mediaQuery; @@ -38,10 +38,9 @@ class Import implements AtRule protected $comments = []; /** - * @param string $mediaQuery * @param int<0, max> $lineNumber */ - public function __construct(URL $location, $mediaQuery, int $lineNumber = 0) + public function __construct(URL $location, ?string $mediaQuery, int $lineNumber = 0) { $this->location = $location; $this->mediaQuery = $mediaQuery; @@ -56,18 +55,12 @@ public function getLineNo(): int return $this->lineNumber; } - /** - * @param URL $location - */ - public function setLocation($location): void + public function setLocation(URL $location): void { $this->location = $location; } - /** - * @return URL - */ - public function getLocation() + public function getLocation(): URL { return $this->location; } @@ -95,14 +88,15 @@ public function atRuleName(): string } /** - * @return array + * @return array{0: URL, 1?: non-empty-string} */ public function atRuleArgs(): array { $result = [$this->location]; - if ($this->mediaQuery) { - \array_push($result, $this->mediaQuery); + if (\is_string($this->mediaQuery) && $this->mediaQuery !== '') { + $result[] = $this->mediaQuery; } + return $result; } @@ -130,10 +124,7 @@ public function setComments(array $comments): void $this->comments = $comments; } - /** - * @return string - */ - public function getMediaQuery() + public function getMediaQuery(): ?string { return $this->mediaQuery; }