6
6
use Sabberworm \CSS \Comment \Commentable ;
7
7
use Sabberworm \CSS \OutputFormat ;
8
8
use Sabberworm \CSS \Parsing \ParserState ;
9
+ use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
9
10
use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
10
11
use Sabberworm \CSS \Renderable ;
11
12
use Sabberworm \CSS \Rule \Rule ;
16
17
*/
17
18
abstract class RuleSet implements Renderable, Commentable
18
19
{
20
+ /**
21
+ * @var array<string, Rule>
22
+ */
19
23
private $ aRules ;
20
24
25
+ /**
26
+ * @var int
27
+ */
21
28
protected $ iLineNo ;
22
29
23
30
/**
24
31
* @var array<array-key, Comment>
25
32
*/
26
33
protected $ aComments ;
27
34
35
+ /**
36
+ * @param int $iLineNo
37
+ */
28
38
public function __construct ($ iLineNo = 0 )
29
39
{
30
40
$ this ->aRules = [];
31
41
$ this ->iLineNo = $ iLineNo ;
32
42
$ this ->aComments = [];
33
43
}
34
44
45
+ /**
46
+ * @return void
47
+ *
48
+ * @throws UnexpectedTokenException
49
+ * @throws UnexpectedEOFException
50
+ */
35
51
public static function parseRuleSet (ParserState $ oParserState , RuleSet $ oRuleSet )
36
52
{
37
53
while ($ oParserState ->comes ('; ' )) {
@@ -76,6 +92,11 @@ public function getLineNo()
76
92
return $ this ->iLineNo ;
77
93
}
78
94
95
+ /**
96
+ * @param Rule|null $oSibling
97
+ *
98
+ * @return void
99
+ */
79
100
public function addRule (Rule $ oRule , Rule $ oSibling = null )
80
101
{
81
102
$ sRule = $ oRule ->getRule ();
@@ -113,19 +134,20 @@ public function addRule(Rule $oRule, Rule $oSibling = null)
113
134
* @example $oRuleSet->getRules('font-')
114
135
* //returns an array of all rules either beginning with font- or matching font.
115
136
*
116
- * @param null |string|Rule $mRule
117
- * pattern to search for. If null, returns all rules.
118
- * if the pattern ends with a dash, all rules starting with the pattern are returned
137
+ * @param Rule |string|null $mRule
138
+ * Pattern to search for. If null, returns all rules.
139
+ * If the pattern ends with a dash, all rules starting with the pattern are returned
119
140
* as well as one matching the pattern with the dash excluded.
120
- * passing a Rule behaves like calling getRules($mRule->getRule()).
141
+ * Passing a Rule behaves like calling ` getRules($mRule->getRule())` .
121
142
*
122
- * @return array<int, Rule> Rules.
143
+ * @return array<int, Rule>
123
144
*/
124
145
public function getRules ($ mRule = null )
125
146
{
126
147
if ($ mRule instanceof Rule) {
127
148
$ mRule = $ mRule ->getRule ();
128
149
}
150
+ /** @var array<int, Rule> $aResult */
129
151
$ aResult = [];
130
152
foreach ($ this ->aRules as $ sName => $ aRules ) {
131
153
// Either no search rule is given or the search rule matches the found rule exactly
@@ -150,9 +172,11 @@ public function getRules($mRule = null)
150
172
}
151
173
152
174
/**
153
- * Override all the rules of this set.
175
+ * Overrides all the rules of this set.
154
176
*
155
- * @param Rule[] $aRules The rules to override with.
177
+ * @param array<array-key, Rule> $aRules The rules to override with.
178
+ *
179
+ * @return void
156
180
*/
157
181
public function setRules (array $ aRules )
158
182
{
@@ -170,15 +194,16 @@ public function setRules(array $aRules)
170
194
* like `{ background-color: green; background-color; rgba(0, 127, 0, 0.7); }` will only yield an associative array
171
195
* containing the rgba-valued rule while `getRules()` would yield an indexed array containing both.
172
196
*
173
- * @param string $mRule
174
- * pattern to search for. If null, returns all rules. if the pattern ends with a dash,
197
+ * @param Rule| string|null $mRule $mRule
198
+ * Pattern to search for. If null, returns all rules. If the pattern ends with a dash,
175
199
* all rules starting with the pattern are returned as well as one matching the pattern with the dash
176
- * excluded. passing a Rule behaves like calling getRules($mRule->getRule()).
200
+ * excluded. Passing a Rule behaves like calling ` getRules($mRule->getRule())` .
177
201
*
178
- * @return Rule[] Rules.
202
+ * @return array<string, Rule>
179
203
*/
180
204
public function getRulesAssoc ($ mRule = null )
181
205
{
206
+ /** @var array<string, Rule> $aResult */
182
207
$ aResult = [];
183
208
foreach ($ this ->getRules ($ mRule ) as $ oRule ) {
184
209
$ aResult [$ oRule ->getRule ()] = $ oRule ;
@@ -193,12 +218,14 @@ public function getRulesAssoc($mRule = null)
193
218
* If given a name, it will remove all rules by that name.
194
219
*
195
220
* Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would
196
- * remove all rules with the same name. To get the old behaviour, use removeRule($oRule->getRule()).
221
+ * remove all rules with the same name. To get the old behaviour, use ` removeRule($oRule->getRule())` .
197
222
*
198
- * @param null |string|Rule $mRule
223
+ * @param Rule |string|null $mRule
199
224
* pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash,
200
225
* all rules starting with the pattern are removed as well as one matching the pattern with the dash
201
226
* excluded. Passing a Rule behaves matches by identity.
227
+ *
228
+ * @return void
202
229
*/
203
230
public function removeRule ($ mRule )
204
231
{
@@ -270,7 +297,7 @@ public function render(OutputFormat $oOutputFormat)
270
297
}
271
298
272
299
/**
273
- * @param array<array-key , Comment> $aComments
300
+ * @param array<string , Comment> $aComments
274
301
*
275
302
* @return void
276
303
*/
@@ -280,15 +307,15 @@ public function addComments(array $aComments)
280
307
}
281
308
282
309
/**
283
- * @return array<array-key , Comment>
310
+ * @return array<string , Comment>
284
311
*/
285
312
public function getComments ()
286
313
{
287
314
return $ this ->aComments ;
288
315
}
289
316
290
317
/**
291
- * @param array<array-key , Comment> $aComments
318
+ * @param array<string , Comment> $aComments
292
319
*
293
320
* @return void
294
321
*/
0 commit comments