From f388a543fc6eb152eb1de4361602a60762ecfd92 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Tue, 11 Mar 2025 23:58:07 +0100 Subject: [PATCH 1/2] [TASK] Add native type declarations for `atRuleName()` Part of #811 --- CHANGELOG.md | 2 +- src/CSSList/AtRuleBlockList.php | 6 +++++- src/CSSList/KeyFrame.php | 4 ++++ src/Property/AtRule.php | 4 ++-- src/Property/CSSNamespace.php | 2 +- src/Property/Charset.php | 3 +++ src/Property/Import.php | 3 +++ src/RuleSet/AtRuleSet.php | 8 ++++---- 8 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3a0338ab..c14d37603 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ Please also have a look at our - Make all non-private properties `@internal` (#886) - 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) + #964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145) - Add visibility to all class/interface constants (#469) ### Deprecated diff --git a/src/CSSList/AtRuleBlockList.php b/src/CSSList/AtRuleBlockList.php index 2fbe755c3..ad91fe813 100644 --- a/src/CSSList/AtRuleBlockList.php +++ b/src/CSSList/AtRuleBlockList.php @@ -13,7 +13,7 @@ class AtRuleBlockList extends CSSBlockList implements AtRule { /** - * @var string + * @var non-empty-string */ private $type; @@ -23,6 +23,7 @@ class AtRuleBlockList extends CSSBlockList implements AtRule private $arguments; /** + * @param non-empty-string $type * @param int<0, max> $lineNumber */ public function __construct(string $type, string $arguments = '', int $lineNumber = 0) @@ -32,6 +33,9 @@ public function __construct(string $type, string $arguments = '', int $lineNumbe $this->arguments = $arguments; } + /** + * @return non-empty-string + */ public function atRuleName(): string { return $this->type; diff --git a/src/CSSList/KeyFrame.php b/src/CSSList/KeyFrame.php index 40e0823dc..70b27399e 100644 --- a/src/CSSList/KeyFrame.php +++ b/src/CSSList/KeyFrame.php @@ -7,6 +7,10 @@ use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Property\AtRule; +/** + * Note: When constructing an instance of this class, `setVendorKeyFrame()` must be called directly after construction + * for the instance to be valid. + */ class KeyFrame extends CSSList implements AtRule { /** diff --git a/src/Property/AtRule.php b/src/Property/AtRule.php index f4b7c7242..f17b42272 100644 --- a/src/Property/AtRule.php +++ b/src/Property/AtRule.php @@ -20,9 +20,9 @@ interface AtRule extends Renderable, Commentable public const BLOCK_RULES = 'media/document/supports/region-style/font-feature-values'; /** - * @return string|null + * @return non-empty-string */ - public function atRuleName(); + public function atRuleName(): string; /** * @return string|null diff --git a/src/Property/CSSNamespace.php b/src/Property/CSSNamespace.php index b76044568..32a0419d8 100644 --- a/src/Property/CSSNamespace.php +++ b/src/Property/CSSNamespace.php @@ -101,7 +101,7 @@ public function setPrefix($prefix): void } /** - * @return string + * @return non-empty-string */ public function atRuleName(): string { diff --git a/src/Property/Charset.php b/src/Property/Charset.php index 59675665c..97510a1cf 100644 --- a/src/Property/Charset.php +++ b/src/Property/Charset.php @@ -84,6 +84,9 @@ public function render(OutputFormat $outputFormat): string return "{$outputFormat->comments($this)}@charset {$this->charset->render($outputFormat)};"; } + /** + * @return non-empty-string + */ public function atRuleName(): string { return 'charset'; diff --git a/src/Property/Import.php b/src/Property/Import.php index 77ae17cfe..41059738d 100644 --- a/src/Property/Import.php +++ b/src/Property/Import.php @@ -86,6 +86,9 @@ public function render(OutputFormat $outputFormat): string . ($this->mediaQuery === null ? '' : ' ' . $this->mediaQuery) . ';'; } + /** + * @return non-empty-string + */ public function atRuleName(): string { return 'import'; diff --git a/src/RuleSet/AtRuleSet.php b/src/RuleSet/AtRuleSet.php index 96fed1828..c8fb79e33 100644 --- a/src/RuleSet/AtRuleSet.php +++ b/src/RuleSet/AtRuleSet.php @@ -16,7 +16,7 @@ class AtRuleSet extends RuleSet implements AtRule { /** - * @var string + * @var non-empty-string */ private $type; @@ -26,7 +26,7 @@ class AtRuleSet extends RuleSet implements AtRule private $arguments; /** - * @param string $type + * @param non-empty-string $type * @param string $arguments * @param int<0, max> $lineNumber */ @@ -38,9 +38,9 @@ public function __construct($type, $arguments = '', int $lineNumber = 0) } /** - * @return string + * @return non-empty-string */ - public function atRuleName() + public function atRuleName(): string { return $this->type; } From 14300c160951d196c387774e77fe6d1e1c851b3c Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 12 Mar 2025 09:09:03 +0100 Subject: [PATCH 2/2] Drop obsolete comment --- src/CSSList/KeyFrame.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CSSList/KeyFrame.php b/src/CSSList/KeyFrame.php index 70b27399e..40e0823dc 100644 --- a/src/CSSList/KeyFrame.php +++ b/src/CSSList/KeyFrame.php @@ -7,10 +7,6 @@ use Sabberworm\CSS\OutputFormat; use Sabberworm\CSS\Property\AtRule; -/** - * Note: When constructing an instance of this class, `setVendorKeyFrame()` must be called directly after construction - * for the instance to be valid. - */ class KeyFrame extends CSSList implements AtRule { /**