-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLEANUP] Avoid Hungarian notation in RuleSet
#1004
base: main
Are you sure you want to change the base?
Conversation
I'm not sure about the naming at all and would appreciate a critical eye (and suggestions). |
9cf23ca
to
51331a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can only see one improvement on naming. W3C have changed the names of the abstract concepts over time, which has left us with some class names that no longer correspond.
51331a3
to
4a7d4cd
Compare
4a7d4cd
to
9dc285e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may have missed some changes in previous review. I've suggested a few more naming improvements.
$rulesCount = \count($rules); | ||
if ($rulesCount > 0) { | ||
$last = $rules[$rulesCount - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The local $rulesCount
is probably unnecessary here, since count
is atomic (!== []
might be possible if the type of $rules
can be guaranteed to be an array), and end()
could be used to access the last element. But that's beyond the scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! I've created #1015 to track this.
src/RuleSet/RuleSet.php
Outdated
} | ||
/** @var array<int, Rule> $result */ | ||
$result = []; | ||
foreach ($this->aRules as $sName => $aRules) { | ||
foreach ($this->rules as $ruleName => $rule) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use $propertyName
here instead of $ruleName
?
src/RuleSet/RuleSet.php
Outdated
@@ -222,34 +223,34 @@ public function getRulesAssoc($mRule = null) | |||
* Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would | |||
* remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`. | |||
* | |||
* @param Rule|string|null $mRule | |||
* @param Rule|string|null $removalPattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would prefer $searchPattern
again here. The rules to be removed still have to be searched for.
src/RuleSet/RuleSet.php
Outdated
@@ -222,34 +223,34 @@ public function getRulesAssoc($mRule = null) | |||
* Note: this is different from pre-v.2.0 behaviour of PHP-CSS-Parser, where passing a Rule instance would | |||
* remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`. | |||
* | |||
* @param Rule|string|null $mRule | |||
* @param Rule|string|null $removalPattern | |||
* pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mentions the parameter by name, and would also need updating. Though could perhaps be modified to avoid being self-referential.
src/RuleSet/RuleSet.php
Outdated
$sRule = $mRule->getRule(); | ||
if (!isset($this->aRules[$sRule])) { | ||
if ($removalPattern instanceof Rule) { | ||
$removalRule = $removalPattern->getRule(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe $propertyToRemove
instead of $removalRule
.
Updated and repushed. |
7d8c5a4
to
76753c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might have been better to have this PR in more manageable chunks. But we are where we are, and we are nearly there.
I found one more variable that could be better-renamed.
src/RuleSet/RuleSet.php
Outdated
} | ||
} | ||
} else { | ||
foreach ($this->aRules as $sName => $aRules) { | ||
foreach ($this->rules as $ruleName => $rules) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$propertyName
rather than $ruleName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actaully I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not a nested RuleSet
then 'property name' is correct. But I'm not sure otherwise. Perhaps $propertyOrRuleName
may be better throughout.
29f1010
to
5fd54e3
Compare
Also improve some names. (This class still in in urgent need of refactoring to improve type safety and make clear naming easier.) Part of #756
5fd54e3
to
3fb7d71
Compare
3fb7d71
to
52846cb
Compare
Okay, I'll split this up. |
Also improve some names. (This class still in in urgent need of refactoring to improve type safety and make clear naming easier.)
Part of #756