From 0f080ffb94741f9c8a533f3c412101ed3606021d Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Mon, 16 Feb 2026 19:05:51 +0000 Subject: [PATCH] [TASK] Rename `RuleContainer` to `DeclarationList` It contains property declarations not rules, and describing it as a 'list' rather than a 'container' seems more apt, as the declarations are ordered. Changes to use the new interface name in the source code and tests will be submitted as follow-up PRs. --- CHANGELOG.md | 3 ++ config/phpstan.neon | 1 + src/RuleSet/DeclarationList.php | 77 +++++++++++++++++++++++++++++++++ src/RuleSet/RuleContainer.php | 71 ++---------------------------- 4 files changed, 84 insertions(+), 68 deletions(-) create mode 100644 src/RuleSet/DeclarationList.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e3ecb8..224916a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Please also have a look at our ### Changed +- `RuleSet\RuleContainer` is renamed to `RuleSet\DeclarationList` (#1530) - Methods like `setRule()` in `RuleSet` and `DeclarationBlock` have been renamed to `setDeclaration()`, etc. (#1521) - `Rule\Rule` class is renamed to `Property\Declaration` @@ -35,6 +36,8 @@ Please also have a look at our ### Deprecated +- `RuleSet\RuleContainer` is deprecated; use `RuleSet\DeclarationList` instead + (#1530) - Methods like `setRule()` in `RuleSet` and `DeclarationBlock` are deprecated; there are direct replacements such as `setDeclaration()` (#1521) - `Rule\Rule` class is deprecated; `Property\Declaration` is a direct diff --git a/config/phpstan.neon b/config/phpstan.neon index cfdfefe1..84416ade 100644 --- a/config/phpstan.neon +++ b/config/phpstan.neon @@ -17,6 +17,7 @@ parameters: bootstrapFiles: - %currentWorkingDirectory%/src/Rule/Rule.php + - %currentWorkingDirectory%/src/RuleSet/RuleContainer.php type_perfect: no_mixed_property: true diff --git a/src/RuleSet/DeclarationList.php b/src/RuleSet/DeclarationList.php new file mode 100644 index 00000000..b1e67915 --- /dev/null +++ b/src/RuleSet/DeclarationList.php @@ -0,0 +1,77 @@ + $declarations + */ + public function setDeclarations(array $declarations): void; + + /** + * @return array, Declaration> + */ + public function getDeclarations(?string $searchPattern = null): array; + + /** + * @return array + */ + public function getDeclarationsAssociative(?string $searchPattern = null): array; + + /** + * @deprecated in v9.2, will be removed in v10.0; use `addDeclaration()` instead. + */ + public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void; + + /** + * @deprecated in v9.2, will be removed in v10.0; use `removeDeclaration()` instead. + */ + public function removeRule(Declaration $declarationToRemove): void; + + /** + * @deprecated in v9.2, will be removed in v10.0; use `removeMatchingDeclarations()` instead. + */ + public function removeMatchingRules(string $searchPattern): void; + + /** + * @deprecated in v9.2, will be removed in v10.0; use `removeAllDeclarations()` instead. + */ + public function removeAllRules(): void; + + /** + * @param array $declarations + * + * @deprecated in v9.2, will be removed in v10.0; use `setDeclarations()` instead. + */ + public function setRules(array $declarations): void; + + /** + * @return array, Declaration> + * + * @deprecated in v9.2, will be removed in v10.0; use `getDeclarations()` instead. + */ + public function getRules(?string $searchPattern = null): array; + + /** + * @return array + * + * @deprecated in v9.2, will be removed in v10.0; use `getDeclarationsAssociative()` instead. + */ + public function getRulesAssoc(?string $searchPattern = null): array; +} diff --git a/src/RuleSet/RuleContainer.php b/src/RuleSet/RuleContainer.php index 2767d505..daaf1309 100644 --- a/src/RuleSet/RuleContainer.php +++ b/src/RuleSet/RuleContainer.php @@ -4,74 +4,9 @@ namespace Sabberworm\CSS\RuleSet; -use Sabberworm\CSS\Property\Declaration; +use function Safe\class_alias; /** - * Represents a CSS item that contains `Declaration`s, defining the methods to manipulate them. + * @deprecated in v9.2, will be removed in v10.0. Use `DeclarationList` instead, which is a direct replacement. */ -interface RuleContainer -{ - public function addDeclaration(Declaration $declarationToAdd, ?Declaration $sibling = null): void; - - public function removeDeclaration(Declaration $declarationToRemove): void; - - public function removeMatchingDeclarations(string $searchPattern): void; - - public function removeAllDeclarations(): void; - - /** - * @param array $declarations - */ - public function setDeclarations(array $declarations): void; - - /** - * @return array, Declaration> - */ - public function getDeclarations(?string $searchPattern = null): array; - - /** - * @return array - */ - public function getDeclarationsAssociative(?string $searchPattern = null): array; - - /** - * @deprecated in v9.2, will be removed in v10.0; use `addDeclaration()` instead. - */ - public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void; - - /** - * @deprecated in v9.2, will be removed in v10.0; use `removeDeclaration()` instead. - */ - public function removeRule(Declaration $declarationToRemove): void; - - /** - * @deprecated in v9.2, will be removed in v10.0; use `removeMatchingDeclarations()` instead. - */ - public function removeMatchingRules(string $searchPattern): void; - - /** - * @deprecated in v9.2, will be removed in v10.0; use `removeAllDeclarations()` instead. - */ - public function removeAllRules(): void; - - /** - * @param array $declarations - * - * @deprecated in v9.2, will be removed in v10.0; use `setDeclarations()` instead. - */ - public function setRules(array $declarations): void; - - /** - * @return array, Declaration> - * - * @deprecated in v9.2, will be removed in v10.0; use `getDeclarations()` instead. - */ - public function getRules(?string $searchPattern = null): array; - - /** - * @return array - * - * @deprecated in v9.2, will be removed in v10.0; use `getDeclarationsAssociative()` instead. - */ - public function getRulesAssoc(?string $searchPattern = null): array; -} +class_alias(DeclarationList::class, RuleContainer::class);