25
25
abstract class RuleSet implements Renderable, Commentable
26
26
{
27
27
/**
28
+ * the rules in this rule set, using the property name as the key
29
+ *
28
30
* @var array<string, Rule>
29
31
*/
30
32
private $ rules = [];
@@ -153,14 +155,15 @@ public function getRules($searchPattern = null)
153
155
}
154
156
/** @var array<int, Rule> $result */
155
157
$ result = [];
156
- foreach ($ this ->rules as $ ruleName => $ rule ) {
158
+ foreach ($ this ->rules as $ propertyName => $ rule ) {
157
159
// Either no search rule is given or the search rule matches the found rule exactly
158
160
// or the search rule ends in “-” and the found rule starts with the search rule.
159
161
if (
160
- !$ searchPattern || $ ruleName === $ searchPattern
162
+ !$ searchPattern || $ propertyName === $ searchPattern
161
163
|| (
162
164
\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
163
- && (\strpos ($ ruleName , $ searchPattern ) === 0 || $ ruleName === \substr ($ searchPattern , 0 , -1 ))
165
+ && (\strpos ($ propertyName , $ searchPattern ) === 0
166
+ || $ propertyName === \substr ($ searchPattern , 0 , -1 ))
164
167
)
165
168
) {
166
169
$ result = \array_merge ($ result , $ rule );
@@ -223,21 +226,21 @@ public function getRulesAssoc($searchPattern = null)
223
226
* Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would
224
227
* remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`.
225
228
*
226
- * @param Rule|string|null $removalPattern
227
- * pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash,
229
+ * @param Rule|string|null $searchPattern
230
+ * pattern to remove. If this is ` null` , all rules are removed. If the pattern ends in a dash,
228
231
* all rules starting with the pattern are removed as well as one matching the pattern with the dash
229
232
* excluded. Passing a Rule behaves matches by identity.
230
233
*/
231
- public function removeRule ($ removalPattern ): void
234
+ public function removeRule ($ searchPattern ): void
232
235
{
233
- if ($ removalPattern instanceof Rule) {
234
- $ removalRule = $ removalPattern ->getRule ();
235
- if (!isset ($ this ->rules [$ removalRule ])) {
236
+ if ($ searchPattern instanceof Rule) {
237
+ $ propertyToRemove = $ searchPattern ->getRule ();
238
+ if (!isset ($ this ->rules [$ propertyToRemove ])) {
236
239
return ;
237
240
}
238
- foreach ($ this ->rules [$ removalRule ] as $ key => $ rule ) {
239
- if ($ rule === $ removalPattern ) {
240
- unset($ this ->rules [$ removalRule ][$ key ]);
241
+ foreach ($ this ->rules [$ propertyToRemove ] as $ key => $ rule ) {
242
+ if ($ rule === $ searchPattern ) {
243
+ unset($ this ->rules [$ propertyToRemove ][$ key ]);
241
244
}
242
245
}
243
246
} else {
@@ -246,9 +249,9 @@ public function removeRule($removalPattern): void
246
249
// or the search rule ends in “-” and the found rule starts with the search rule or equals it
247
250
// (without the trailing dash).
248
251
if (
249
- !$ removalPattern || $ ruleName === $ removalPattern
250
- || (\strrpos ($ removalPattern , '- ' ) === \strlen ($ removalPattern ) - \strlen ('- ' )
251
- && (\strpos ($ ruleName , $ removalPattern ) === 0 || $ ruleName === \substr ($ removalPattern , 0 , -1 )))
252
+ !$ searchPattern || $ ruleName === $ searchPattern
253
+ || (\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
254
+ && (\strpos ($ ruleName , $ searchPattern ) === 0 || $ ruleName === \substr ($ searchPattern , 0 , -1 )))
252
255
) {
253
256
unset($ this ->rules [$ ruleName ]);
254
257
}
0 commit comments