@@ -209,18 +209,12 @@ public function getRulesAssoc($searchPattern = null): array
209209 }
210210
211211 /**
212- * Removes a rule from this RuleSet. This accepts all the possible values that `getRules()` accepts.
213- *
214- * If given a Rule, it will only remove this particular rule (by identity).
215- * If given a name, it will remove all rules by that name.
216- *
217- * Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would
218- * remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`.
212+ * Removes a `Rule` from this `RuleSet` by identity.
219213 *
220214 * @param Rule|string|null $searchPattern
221- * pattern to remove. If null, all rules are removed. If the pattern ends in a dash,
222- * all rules starting with the pattern are removed as well as one matching the pattern with the dash
223- * excluded. Passing a Rule behaves matches by identity .
215+ * `Rule` to remove.
216+ * Passing a `string` or `null` is deprecated in version 8.9.0, and will no longer work from v9.0.
217+ * Use `removeMatchingRules()` instead .
224218 */
225219 public function removeRule ($ searchPattern ): void
226220 {
@@ -235,18 +229,31 @@ public function removeRule($searchPattern): void
235229 }
236230 }
237231 } else {
238- foreach ($ this ->rules as $ propertyName => $ rules ) {
239- // Either no search rule is given or the search rule matches the found rule exactly
240- // or the search rule ends in “-” and the found rule starts with the search rule or equals it
241- // (without the trailing dash).
242- if (
243- $ searchPattern === null || $ propertyName === $ searchPattern
244- || (\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
245- && (\strpos ($ propertyName , $ searchPattern ) === 0
246- || $ propertyName === \substr ($ searchPattern , 0 , -1 )))
247- ) {
248- unset($ this ->rules [$ propertyName ]);
249- }
232+ $ this ->removeMatchingRules ($ searchPattern );
233+ }
234+ }
235+
236+ /**
237+ * Removes rules by property name or search pattern.
238+ *
239+ * @param string|null $searchPattern
240+ * pattern to remove. If null, all rules are removed. If the pattern ends in a dash,
241+ * all rules starting with the pattern are removed as well as one matching the pattern with the dash
242+ * excluded.
243+ */
244+ public function removeMatchingRules (?string $ searchPattern ): void
245+ {
246+ foreach ($ this ->rules as $ propertyName => $ rules ) {
247+ // Either no search rule is given or the search rule matches the found rule exactly
248+ // or the search rule ends in “-” and the found rule starts with the search rule or equals it
249+ // (without the trailing dash).
250+ if (
251+ $ searchPattern === null || $ propertyName === $ searchPattern
252+ || (\strrpos ($ searchPattern , '- ' ) === \strlen ($ searchPattern ) - \strlen ('- ' )
253+ && (\strpos ($ propertyName , $ searchPattern ) === 0
254+ || $ propertyName === \substr ($ searchPattern , 0 , -1 )))
255+ ) {
256+ unset($ this ->rules [$ propertyName ]);
250257 }
251258 }
252259 }
0 commit comments