@@ -212,18 +212,12 @@ public function getRulesAssoc($searchPattern = null): array
212212 }
213213
214214 /**
215- * Removes a rule from this RuleSet. This accepts all the possible values that `getRules()` accepts.
216- *
217- * If given a Rule, it will only remove this particular rule (by identity).
218- * If given a name, it will remove all rules by that name.
219- *
220- * Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would
221- * remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`.
215+ * Removes a `Rule` from this `RuleSet` by identity.
222216 *
223217 * @param Rule|string|null $searchPattern
224- * pattern to remove. If null, all rules are removed. If the pattern ends in a dash,
225- * all rules starting with the pattern are removed as well as one matching the pattern with the dash
226- * excluded. Passing a Rule behaves matches by identity .
218+ * `Rule` to remove.
219+ * Passing a `string` or `null` is deprecated in version 8.9.0, and will no longer work from v9.0.
220+ * Use `removeMatchingRules()` instead .
227221 */
228222 public function removeRule ($ searchPattern ): void
229223 {
@@ -238,18 +232,31 @@ public function removeRule($searchPattern): void
238232 }
239233 }
240234 } else {
241- foreach ($ this ->rules as $ propertyName => $ rules ) {
242- // Either no search rule is given or the search rule matches the found rule exactly
243- // or the search rule ends in “-” and the found rule starts with the search rule or equals it
244- // (without the trailing dash).
245- if (
246- $ searchPattern === null || $ propertyName === $ searchPattern
247- || (\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
248- && (\strpos ($ propertyName , $ searchPattern ) === 0
249- || $ propertyName === \substr ($ searchPattern , 0 , -1 )))
250- ) {
251- unset($ this ->rules [$ propertyName ]);
252- }
235+ $ this ->removeMatchingRules ($ searchPattern );
236+ }
237+ }
238+
239+ /**
240+ * Removes rules by property name or search pattern.
241+ *
242+ * @param string|null $searchPattern
243+ * pattern to remove. If null, all rules are removed. If the pattern ends in a dash,
244+ * all rules starting with the pattern are removed as well as one matching the pattern with the dash
245+ * excluded.
246+ */
247+ public function removeMatchingRules (?string $ searchPattern ): void
248+ {
249+ foreach ($ this ->rules as $ propertyName => $ rules ) {
250+ // Either no search rule is given or the search rule matches the found rule exactly
251+ // or the search rule ends in “-” and the found rule starts with the search rule or equals it
252+ // (without the trailing dash).
253+ if (
254+ $ searchPattern === null || $ propertyName === $ searchPattern
255+ || (\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
256+ && (\strpos ($ propertyName , $ searchPattern ) === 0
257+ || $ propertyName === \substr ($ searchPattern , 0 , -1 )))
258+ ) {
259+ unset($ this ->rules [$ propertyName ]);
253260 }
254261 }
255262 }
0 commit comments