66use Sabberworm \CSS \Comment \Commentable ;
77use Sabberworm \CSS \OutputFormat ;
88use Sabberworm \CSS \Parsing \ParserState ;
9+ use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
910use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
1011use Sabberworm \CSS \Renderable ;
1112use Sabberworm \CSS \Rule \Rule ;
1617 */
1718abstract class RuleSet implements Renderable, Commentable
1819{
20+ /**
21+ * @var array<string, Rule>
22+ */
1923 private $ aRules ;
2024
25+ /**
26+ * @var int
27+ */
2128 protected $ iLineNo ;
2229
2330 /**
2431 * @var array<array-key, Comment>
2532 */
2633 protected $ aComments ;
2734
35+ /**
36+ * @param int $iLineNo
37+ */
2838 public function __construct ($ iLineNo = 0 )
2939 {
3040 $ this ->aRules = [];
3141 $ this ->iLineNo = $ iLineNo ;
3242 $ this ->aComments = [];
3343 }
3444
45+ /**
46+ * @return void
47+ *
48+ * @throws UnexpectedTokenException
49+ * @throws UnexpectedEOFException
50+ */
3551 public static function parseRuleSet (ParserState $ oParserState , RuleSet $ oRuleSet )
3652 {
3753 while ($ oParserState ->comes ('; ' )) {
@@ -76,6 +92,11 @@ public function getLineNo()
7692 return $ this ->iLineNo ;
7793 }
7894
95+ /**
96+ * @param Rule|null $oSibling
97+ *
98+ * @return void
99+ */
79100 public function addRule (Rule $ oRule , Rule $ oSibling = null )
80101 {
81102 $ sRule = $ oRule ->getRule ();
@@ -113,19 +134,20 @@ public function addRule(Rule $oRule, Rule $oSibling = null)
113134 * @example $oRuleSet->getRules('font-')
114135 * //returns an array of all rules either beginning with font- or matching font.
115136 *
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
119140 * 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())` .
121142 *
122- * @return array<int, Rule> Rules.
143+ * @return array<int, Rule>
123144 */
124145 public function getRules ($ mRule = null )
125146 {
126147 if ($ mRule instanceof Rule) {
127148 $ mRule = $ mRule ->getRule ();
128149 }
150+ /** @var array<int, Rule> $aResult */
129151 $ aResult = [];
130152 foreach ($ this ->aRules as $ sName => $ aRules ) {
131153 // Either no search rule is given or the search rule matches the found rule exactly
@@ -150,9 +172,11 @@ public function getRules($mRule = null)
150172 }
151173
152174 /**
153- * Override all the rules of this set.
175+ * Overrides all the rules of this set.
154176 *
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
156180 */
157181 public function setRules (array $ aRules )
158182 {
@@ -170,15 +194,16 @@ public function setRules(array $aRules)
170194 * like `{ background-color: green; background-color; rgba(0, 127, 0, 0.7); }` will only yield an associative array
171195 * containing the rgba-valued rule while `getRules()` would yield an indexed array containing both.
172196 *
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,
175199 * 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())` .
177201 *
178- * @return Rule[] Rules.
202+ * @return array<string, Rule>
179203 */
180204 public function getRulesAssoc ($ mRule = null )
181205 {
206+ /** @var array<string, Rule> $aResult */
182207 $ aResult = [];
183208 foreach ($ this ->getRules ($ mRule ) as $ oRule ) {
184209 $ aResult [$ oRule ->getRule ()] = $ oRule ;
@@ -193,12 +218,14 @@ public function getRulesAssoc($mRule = null)
193218 * If given a name, it will remove all rules by that name.
194219 *
195220 * 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())` .
197222 *
198- * @param null |string|Rule $mRule
223+ * @param Rule |string|null $mRule
199224 * pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash,
200225 * all rules starting with the pattern are removed as well as one matching the pattern with the dash
201226 * excluded. Passing a Rule behaves matches by identity.
227+ *
228+ * @return void
202229 */
203230 public function removeRule ($ mRule )
204231 {
@@ -270,7 +297,7 @@ public function render(OutputFormat $oOutputFormat)
270297 }
271298
272299 /**
273- * @param array<array-key , Comment> $aComments
300+ * @param array<string , Comment> $aComments
274301 *
275302 * @return void
276303 */
@@ -280,15 +307,15 @@ public function addComments(array $aComments)
280307 }
281308
282309 /**
283- * @return array<array-key , Comment>
310+ * @return array<string , Comment>
284311 */
285312 public function getComments ()
286313 {
287314 return $ this ->aComments ;
288315 }
289316
290317 /**
291- * @param array<array-key , Comment> $aComments
318+ * @param array<string , Comment> $aComments
292319 *
293320 * @return void
294321 */
0 commit comments