diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ed3cf5c..69831196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,9 @@ Please also have a look at our ### Changed +- `RuleSet::removeRule()` now only allows `Rule` as the parameter + (implementing classes are `AtRuleSet` and `DeclarationBlock`); + use `removeMatchingRules()` or `removeAllRules()` for other functions (#1255) - `RuleSet::getRules()` and `getRulesAssoc()` now only allow `string` or `null` as the parameter (implementing classes are `AtRuleSet` and `DeclarationBlock`) (#1253) diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index e3cd629a..e1a07f57 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -206,28 +206,17 @@ public function getRulesAssoc(?string $searchPattern = null): array /** * Removes a `Rule` from this `RuleSet` by identity. - * - * @param Rule|string|null $searchPattern - * `Rule` to remove. - * Passing a `string` or `null` is deprecated in version 8.9.0, and will no longer work from v9.0. - * Use `removeMatchingRules()` or `removeAllRules()` instead. */ - public function removeRule($searchPattern): void + public function removeRule(Rule $ruleToRemove): void { - if ($searchPattern instanceof Rule) { - $nameOfPropertyToRemove = $searchPattern->getRule(); - if (!isset($this->rules[$nameOfPropertyToRemove])) { - return; - } - foreach ($this->rules[$nameOfPropertyToRemove] as $key => $rule) { - if ($rule === $searchPattern) { - unset($this->rules[$nameOfPropertyToRemove][$key]); - } + $nameOfPropertyToRemove = $ruleToRemove->getRule(); + if (!isset($this->rules[$nameOfPropertyToRemove])) { + return; + } + foreach ($this->rules[$nameOfPropertyToRemove] as $key => $rule) { + if ($rule === $ruleToRemove) { + unset($this->rules[$nameOfPropertyToRemove][$key]); } - } elseif ($searchPattern !== null) { - $this->removeMatchingRules($searchPattern); - } else { - $this->removeAllRules(); } }