Skip to content

Commit bddb086

Browse files
authored
[TASK] Allow only Rule to be passed to RuleSet::removeRule() (#1255)
Relates to #1247.
1 parent 9706931 commit bddb086

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Please also have a look at our
3131

3232
### Changed
3333

34+
- `RuleSet::removeRule()` now only allows `Rule` as the parameter
35+
(implementing classes are `AtRuleSet` and `DeclarationBlock`);
36+
use `removeMatchingRules()` or `removeAllRules()` for other functions (#1255)
3437
- `RuleSet::getRules()` and `getRulesAssoc()` now only allow `string` or `null`
3538
as the parameter (implementing classes are `AtRuleSet` and `DeclarationBlock`)
3639
(#1253)

src/RuleSet/RuleSet.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,28 +206,17 @@ public function getRulesAssoc(?string $searchPattern = null): array
206206

207207
/**
208208
* Removes a `Rule` from this `RuleSet` by identity.
209-
*
210-
* @param Rule|string|null $searchPattern
211-
* `Rule` to remove.
212-
* Passing a `string` or `null` is deprecated in version 8.9.0, and will no longer work from v9.0.
213-
* Use `removeMatchingRules()` or `removeAllRules()` instead.
214209
*/
215-
public function removeRule($searchPattern): void
210+
public function removeRule(Rule $ruleToRemove): void
216211
{
217-
if ($searchPattern instanceof Rule) {
218-
$nameOfPropertyToRemove = $searchPattern->getRule();
219-
if (!isset($this->rules[$nameOfPropertyToRemove])) {
220-
return;
221-
}
222-
foreach ($this->rules[$nameOfPropertyToRemove] as $key => $rule) {
223-
if ($rule === $searchPattern) {
224-
unset($this->rules[$nameOfPropertyToRemove][$key]);
225-
}
212+
$nameOfPropertyToRemove = $ruleToRemove->getRule();
213+
if (!isset($this->rules[$nameOfPropertyToRemove])) {
214+
return;
215+
}
216+
foreach ($this->rules[$nameOfPropertyToRemove] as $key => $rule) {
217+
if ($rule === $ruleToRemove) {
218+
unset($this->rules[$nameOfPropertyToRemove][$key]);
226219
}
227-
} elseif ($searchPattern !== null) {
228-
$this->removeMatchingRules($searchPattern);
229-
} else {
230-
$this->removeAllRules();
231220
}
232221
}
233222

0 commit comments

Comments
 (0)