Skip to content

[CLEANUP] Avoid Hungarian notation for rules #1024

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

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class RuleSet implements Renderable, Commentable
/**
* @var array<string, Rule>
*/
private $aRules = [];
private $rules = [];

/**
* @var int<0, max>
Expand Down Expand Up @@ -104,14 +104,14 @@ public function getLineNo(): int
public function addRule(Rule $rule, ?Rule $oSibling = null): void
{
$sRule = $rule->getRule();
if (!isset($this->aRules[$sRule])) {
$this->aRules[$sRule] = [];
if (!isset($this->rules[$sRule])) {
$this->rules[$sRule] = [];
}

$position = \count($this->aRules[$sRule]);
$position = \count($this->rules[$sRule]);

if ($oSibling !== null) {
$iSiblingPos = \array_search($oSibling, $this->aRules[$sRule], true);
$iSiblingPos = \array_search($oSibling, $this->rules[$sRule], true);
if ($iSiblingPos !== false) {
$position = $iSiblingPos;
$rule->setPosition($oSibling->getLineNo(), $oSibling->getColNo() - 1);
Expand All @@ -127,7 +127,7 @@ public function addRule(Rule $rule, ?Rule $oSibling = null): void
}
}

\array_splice($this->aRules[$sRule], $position, 0, [$rule]);
\array_splice($this->rules[$sRule], $position, 0, [$rule]);
}

/**
Expand All @@ -153,7 +153,7 @@ public function getRules($mRule = null)
}
/** @var array<int, Rule> $result */
$result = [];
foreach ($this->aRules as $sName => $aRules) {
foreach ($this->rules as $sName => $rules) {
// Either no search rule is given or the search rule matches the found rule exactly
// or the search rule ends in “-” and the found rule starts with the search rule.
if (
Expand All @@ -163,7 +163,7 @@ public function getRules($mRule = null)
&& (\strpos($sName, $mRule) === 0 || $sName === \substr($mRule, 0, -1))
)
) {
$result = \array_merge($result, $aRules);
$result = \array_merge($result, $rules);
}
}
\usort($result, static function (Rule $first, Rule $second): int {
Expand All @@ -178,12 +178,12 @@ public function getRules($mRule = null)
/**
* Overrides all the rules of this set.
*
* @param array<array-key, Rule> $aRules The rules to override with.
* @param array<array-key, Rule> $rules The rules to override with.
*/
public function setRules(array $aRules): void
public function setRules(array $rules): void
{
$this->aRules = [];
foreach ($aRules as $rule) {
$this->rules = [];
foreach ($rules as $rule) {
$this->addRule($rule);
}
}
Expand Down Expand Up @@ -231,16 +231,16 @@ public function removeRule($mRule): void
{
if ($mRule instanceof Rule) {
$sRule = $mRule->getRule();
if (!isset($this->aRules[$sRule])) {
if (!isset($this->rules[$sRule])) {
return;
}
foreach ($this->aRules[$sRule] as $key => $rule) {
foreach ($this->rules[$sRule] as $key => $rule) {
if ($rule === $mRule) {
unset($this->aRules[$sRule][$key]);
unset($this->rules[$sRule][$key]);
}
}
} else {
foreach ($this->aRules as $sName => $aRules) {
foreach ($this->rules as $sName => $rules) {
// Either no search rule is given or the search rule matches the found rule exactly
// or the search rule ends in “-” and the found rule starts with the search rule or equals it
// (without the trailing dash).
Expand All @@ -249,7 +249,7 @@ public function removeRule($mRule): void
|| (\strrpos($mRule, '-') === \strlen($mRule) - \strlen('-')
&& (\strpos($sName, $mRule) === 0 || $sName === \substr($mRule, 0, -1)))
) {
unset($this->aRules[$sName]);
unset($this->rules[$sName]);
}
}
}
Expand All @@ -271,8 +271,8 @@ protected function renderRules(OutputFormat $outputFormat)
$result = '';
$isFirst = true;
$oNextLevel = $outputFormat->nextLevel();
foreach ($this->aRules as $aRules) {
foreach ($aRules as $rule) {
foreach ($this->rules as $rules) {
foreach ($rules as $rule) {
Comment on lines +274 to +275
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm struggling to understand how and why this can be doubly-iterated over - since Rule does not appear to be Iterable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don’t understand this either. Either this is broken (and not tested, or never called), or the code somehow still is working fine. 😉

$sRendered = $oNextLevel->safely(static function () use ($rule, $oNextLevel): string {
return $rule->render($oNextLevel);
});
Expand Down