Skip to content

Commit 0f080ff

Browse files
committed
[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.
1 parent 015a17b commit 0f080ff

4 files changed

Lines changed: 84 additions & 68 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Please also have a look at our
1818

1919
### Changed
2020

21+
- `RuleSet\RuleContainer` is renamed to `RuleSet\DeclarationList` (#1530)
2122
- Methods like `setRule()` in `RuleSet` and `DeclarationBlock` have been renamed
2223
to `setDeclaration()`, etc. (#1521)
2324
- `Rule\Rule` class is renamed to `Property\Declaration`
@@ -35,6 +36,8 @@ Please also have a look at our
3536

3637
### Deprecated
3738

39+
- `RuleSet\RuleContainer` is deprecated; use `RuleSet\DeclarationList` instead
40+
(#1530)
3841
- Methods like `setRule()` in `RuleSet` and `DeclarationBlock` are deprecated;
3942
there are direct replacements such as `setDeclaration()` (#1521)
4043
- `Rule\Rule` class is deprecated; `Property\Declaration` is a direct

config/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ parameters:
1717

1818
bootstrapFiles:
1919
- %currentWorkingDirectory%/src/Rule/Rule.php
20+
- %currentWorkingDirectory%/src/RuleSet/RuleContainer.php
2021

2122
type_perfect:
2223
no_mixed_property: true

src/RuleSet/DeclarationList.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sabberworm\CSS\RuleSet;
6+
7+
use Sabberworm\CSS\Property\Declaration;
8+
9+
/**
10+
* Represents a CSS item that contains `Declaration`s, defining the methods to manipulate them.
11+
*/
12+
interface DeclarationList
13+
{
14+
public function addDeclaration(Declaration $declarationToAdd, ?Declaration $sibling = null): void;
15+
16+
public function removeDeclaration(Declaration $declarationToRemove): void;
17+
18+
public function removeMatchingDeclarations(string $searchPattern): void;
19+
20+
public function removeAllDeclarations(): void;
21+
22+
/**
23+
* @param array<Declaration> $declarations
24+
*/
25+
public function setDeclarations(array $declarations): void;
26+
27+
/**
28+
* @return array<int<0, max>, Declaration>
29+
*/
30+
public function getDeclarations(?string $searchPattern = null): array;
31+
32+
/**
33+
* @return array<string, Declaration>
34+
*/
35+
public function getDeclarationsAssociative(?string $searchPattern = null): array;
36+
37+
/**
38+
* @deprecated in v9.2, will be removed in v10.0; use `addDeclaration()` instead.
39+
*/
40+
public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void;
41+
42+
/**
43+
* @deprecated in v9.2, will be removed in v10.0; use `removeDeclaration()` instead.
44+
*/
45+
public function removeRule(Declaration $declarationToRemove): void;
46+
47+
/**
48+
* @deprecated in v9.2, will be removed in v10.0; use `removeMatchingDeclarations()` instead.
49+
*/
50+
public function removeMatchingRules(string $searchPattern): void;
51+
52+
/**
53+
* @deprecated in v9.2, will be removed in v10.0; use `removeAllDeclarations()` instead.
54+
*/
55+
public function removeAllRules(): void;
56+
57+
/**
58+
* @param array<Declaration> $declarations
59+
*
60+
* @deprecated in v9.2, will be removed in v10.0; use `setDeclarations()` instead.
61+
*/
62+
public function setRules(array $declarations): void;
63+
64+
/**
65+
* @return array<int<0, max>, Declaration>
66+
*
67+
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarations()` instead.
68+
*/
69+
public function getRules(?string $searchPattern = null): array;
70+
71+
/**
72+
* @return array<string, Declaration>
73+
*
74+
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarationsAssociative()` instead.
75+
*/
76+
public function getRulesAssoc(?string $searchPattern = null): array;
77+
}

src/RuleSet/RuleContainer.php

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,9 @@
44

55
namespace Sabberworm\CSS\RuleSet;
66

7-
use Sabberworm\CSS\Property\Declaration;
7+
use function Safe\class_alias;
88

99
/**
10-
* Represents a CSS item that contains `Declaration`s, defining the methods to manipulate them.
10+
* @deprecated in v9.2, will be removed in v10.0. Use `DeclarationList` instead, which is a direct replacement.
1111
*/
12-
interface RuleContainer
13-
{
14-
public function addDeclaration(Declaration $declarationToAdd, ?Declaration $sibling = null): void;
15-
16-
public function removeDeclaration(Declaration $declarationToRemove): void;
17-
18-
public function removeMatchingDeclarations(string $searchPattern): void;
19-
20-
public function removeAllDeclarations(): void;
21-
22-
/**
23-
* @param array<Declaration> $declarations
24-
*/
25-
public function setDeclarations(array $declarations): void;
26-
27-
/**
28-
* @return array<int<0, max>, Declaration>
29-
*/
30-
public function getDeclarations(?string $searchPattern = null): array;
31-
32-
/**
33-
* @return array<string, Declaration>
34-
*/
35-
public function getDeclarationsAssociative(?string $searchPattern = null): array;
36-
37-
/**
38-
* @deprecated in v9.2, will be removed in v10.0; use `addDeclaration()` instead.
39-
*/
40-
public function addRule(Declaration $declarationToAdd, ?Declaration $sibling = null): void;
41-
42-
/**
43-
* @deprecated in v9.2, will be removed in v10.0; use `removeDeclaration()` instead.
44-
*/
45-
public function removeRule(Declaration $declarationToRemove): void;
46-
47-
/**
48-
* @deprecated in v9.2, will be removed in v10.0; use `removeMatchingDeclarations()` instead.
49-
*/
50-
public function removeMatchingRules(string $searchPattern): void;
51-
52-
/**
53-
* @deprecated in v9.2, will be removed in v10.0; use `removeAllDeclarations()` instead.
54-
*/
55-
public function removeAllRules(): void;
56-
57-
/**
58-
* @param array<Declaration> $declarations
59-
*
60-
* @deprecated in v9.2, will be removed in v10.0; use `setDeclarations()` instead.
61-
*/
62-
public function setRules(array $declarations): void;
63-
64-
/**
65-
* @return array<int<0, max>, Declaration>
66-
*
67-
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarations()` instead.
68-
*/
69-
public function getRules(?string $searchPattern = null): array;
70-
71-
/**
72-
* @return array<string, Declaration>
73-
*
74-
* @deprecated in v9.2, will be removed in v10.0; use `getDeclarationsAssociative()` instead.
75-
*/
76-
public function getRulesAssoc(?string $searchPattern = null): array;
77-
}
12+
class_alias(DeclarationList::class, RuleContainer::class);

0 commit comments

Comments
 (0)