Skip to content
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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

oliverklee
Copy link
Contributor

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

@oliverklee
Copy link
Contributor Author

I'm not sure about the naming at all and would appreciate a critical eye (and suggestions).

@coveralls
Copy link

coveralls commented Feb 26, 2025

Coverage Status

coverage: 54.598% (-0.06%) from 54.655%
when pulling 52846cb on cleanup/hungarian/ruleset
into 9192d95 on main.

@oliverklee oliverklee force-pushed the cleanup/hungarian/ruleset branch from 9cf23ca to 51331a3 Compare February 26, 2025 18:39
Copy link
Contributor

@JakeQZ JakeQZ left a 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.

Copy link
Contributor

@JakeQZ JakeQZ left a 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.

Comment on lines +123 to +127
$rulesCount = \count($rules);
if ($rulesCount > 0) {
$last = $rules[$rulesCount - 1];
Copy link
Contributor

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.

Copy link
Contributor Author

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.

}
/** @var array<int, Rule> $result */
$result = [];
foreach ($this->aRules as $sName => $aRules) {
foreach ($this->rules as $ruleName => $rule) {
Copy link
Contributor

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?

@@ -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
Copy link
Contributor

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.

@@ -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,
Copy link
Contributor

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.

$sRule = $mRule->getRule();
if (!isset($this->aRules[$sRule])) {
if ($removalPattern instanceof Rule) {
$removalRule = $removalPattern->getRule();
Copy link
Contributor

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.

@oliverklee
Copy link
Contributor Author

Updated and repushed.

@oliverklee oliverklee requested a review from JakeQZ February 27, 2025 10:36
@oliverklee oliverklee force-pushed the cleanup/hungarian/ruleset branch 2 times, most recently from 7d8c5a4 to 76753c6 Compare February 27, 2025 11:18
Copy link
Contributor

@JakeQZ JakeQZ left a 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.

}
}
} else {
foreach ($this->aRules as $sName => $aRules) {
foreach ($this->rules as $ruleName => $rules) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$propertyName rather than $ruleName

Copy link
Contributor

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.

Copy link
Contributor

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.

@oliverklee oliverklee force-pushed the cleanup/hungarian/ruleset branch from 29f1010 to 5fd54e3 Compare February 27, 2025 11:44
@oliverklee oliverklee requested a review from JakeQZ February 27, 2025 11:44
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
@oliverklee oliverklee force-pushed the cleanup/hungarian/ruleset branch from 5fd54e3 to 3fb7d71 Compare February 27, 2025 12:11
@oliverklee oliverklee force-pushed the cleanup/hungarian/ruleset branch from 3fb7d71 to 52846cb Compare February 27, 2025 12:13
@oliverklee oliverklee marked this pull request as draft February 27, 2025 12:13
@oliverklee
Copy link
Contributor Author

Okay, I'll split this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants