Skip to content

Commit 4a47d54

Browse files
committed
Implement more suggestions from code review
1 parent 9dc285e commit 4a47d54

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/RuleSet/RuleSet.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,15 @@ public function getRules($searchPattern = null)
153153
}
154154
/** @var array<int, Rule> $result */
155155
$result = [];
156-
foreach ($this->rules as $ruleName => $rule) {
156+
foreach ($this->rules as $propertyName => $rule) {
157157
// Either no search rule is given or the search rule matches the found rule exactly
158158
// or the search rule ends in “-” and the found rule starts with the search rule.
159159
if (
160-
!$searchPattern || $ruleName === $searchPattern
160+
!$searchPattern || $propertyName === $searchPattern
161161
|| (
162162
\strrpos($searchPattern, '-') === \strlen($searchPattern) - \strlen('-')
163-
&& (\strpos($ruleName, $searchPattern) === 0 || $ruleName === \substr($searchPattern, 0, -1))
163+
&& (\strpos($propertyName, $searchPattern) === 0
164+
|| $propertyName === \substr($searchPattern, 0, -1))
164165
)
165166
) {
166167
$result = \array_merge($result, $rule);
@@ -223,21 +224,21 @@ public function getRulesAssoc($searchPattern = null)
223224
* Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would
224225
* remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`.
225226
*
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,
227+
* @param Rule|string|null $searchPattern
228+
* pattern to remove. If this is `null`, all rules are removed. If the pattern ends in a dash,
228229
* all rules starting with the pattern are removed as well as one matching the pattern with the dash
229230
* excluded. Passing a Rule behaves matches by identity.
230231
*/
231-
public function removeRule($removalPattern): void
232+
public function removeRule($searchPattern): void
232233
{
233-
if ($removalPattern instanceof Rule) {
234-
$removalRule = $removalPattern->getRule();
235-
if (!isset($this->rules[$removalRule])) {
234+
if ($searchPattern instanceof Rule) {
235+
$propertyToRemove = $searchPattern->getRule();
236+
if (!isset($this->rules[$propertyToRemove])) {
236237
return;
237238
}
238-
foreach ($this->rules[$removalRule] as $key => $rule) {
239-
if ($rule === $removalPattern) {
240-
unset($this->rules[$removalRule][$key]);
239+
foreach ($this->rules[$propertyToRemove] as $key => $rule) {
240+
if ($rule === $searchPattern) {
241+
unset($this->rules[$propertyToRemove][$key]);
241242
}
242243
}
243244
} else {
@@ -246,9 +247,9 @@ public function removeRule($removalPattern): void
246247
// or the search rule ends in “-” and the found rule starts with the search rule or equals it
247248
// (without the trailing dash).
248249
if (
249-
!$removalPattern || $ruleName === $removalPattern
250-
|| (\strrpos($removalPattern, '-') === \strlen($removalPattern) - \strlen('-')
251-
&& (\strpos($ruleName, $removalPattern) === 0 || $ruleName === \substr($removalPattern, 0, -1)))
250+
!$searchPattern || $ruleName === $searchPattern
251+
|| (\strrpos($searchPattern, '-') === \strlen($searchPattern) - \strlen('-')
252+
&& (\strpos($ruleName, $searchPattern) === 0 || $ruleName === \substr($searchPattern, 0, -1)))
252253
) {
253254
unset($this->rules[$ruleName]);
254255
}

0 commit comments

Comments
 (0)