Skip to content

Commit 4b3466d

Browse files
committed
Add RuleContainer interface for RuleSet and DeclarationBlock
1 parent 1ce18b7 commit 4b3466d

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

config/phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ parameters:
5454
count: 1
5555
path: ../src/RuleSet/DeclarationBlock.php
5656

57-
-
58-
message: '#^Parameters should have "string\|null" types as the only types passed to this method$#'
59-
identifier: typePerfect.narrowPublicClassMethodParamType
60-
count: 2
61-
path: ../src/RuleSet/DeclarationBlock.php
62-
6357
-
6458
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
6559
identifier: notEqual.notAllowed

src/CSSList/CSSBlockList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Sabberworm\CSS\Property\Selector;
99
use Sabberworm\CSS\Rule\Rule;
1010
use Sabberworm\CSS\RuleSet\DeclarationBlock;
11+
use Sabberworm\CSS\RuleSet\RuleContainer;
1112
use Sabberworm\CSS\RuleSet\RuleSet;
1213
use Sabberworm\CSS\Value\CSSFunction;
1314
use Sabberworm\CSS\Value\Value;
@@ -97,7 +98,7 @@ public function getAllValues(
9798
);
9899
}
99100
}
100-
} elseif ($element instanceof RuleSet || $element instanceof DeclarationBlock) {
101+
} elseif ($element instanceof RuleContainer) {
101102
foreach ($element->getRules($ruleSearchPattern) as $rule) {
102103
$result = \array_merge(
103104
$result,

src/RuleSet/DeclarationBlock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*
3131
* Note that `CSSListItem` extends both `Commentable` and `Renderable`, so those interfaces must also be implemented.
3232
*/
33-
class DeclarationBlock implements CSSElement, CSSListItem, Positionable
33+
class DeclarationBlock implements CSSElement, CSSListItem, Positionable, RuleContainer
3434
{
3535
use CommentContainer;
3636
use Position;

src/RuleSet/RuleContainer.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sabberworm\CSS\RuleSet;
6+
7+
use Sabberworm\CSS\Rule\Rule;
8+
9+
/**
10+
* Represents a CSS item that contains `Rules`, defining the methods to manipulate them.
11+
*/
12+
interface RuleContainer
13+
{
14+
public function addRule(Rule $ruleToAdd, ?Rule $sibling = null): void;
15+
16+
public function removeRule(Rule $ruleToRemove): void;
17+
18+
public function removeMatchingRules(string $searchPattern): void;
19+
20+
public function removeAllRules(): void;
21+
22+
/**
23+
* @param array<Rule> $rules
24+
*/
25+
public function setRules(array $rules): void;
26+
27+
/**
28+
* @return array<int<0, max>, Rule>
29+
*/
30+
public function getRules(?string $searchPattern = null): array;
31+
32+
/**
33+
* @return array<string, Rule>
34+
*/
35+
public function getRulesAssoc(?string $searchPattern = null): array;
36+
}

src/RuleSet/RuleSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* Note that `CSSListItem` extends both `Commentable` and `Renderable`, so those interfaces must also be implemented.
2828
*/
29-
class RuleSet implements CSSElement, CSSListItem, Positionable
29+
class RuleSet implements CSSElement, CSSListItem, Positionable, RuleContainer
3030
{
3131
use CommentContainer;
3232
use Position;

0 commit comments

Comments
 (0)