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 for oRule/oRuleSet #835

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected function allValues(
$this->allValues($oContent, $result, $searchString, $searchInFunctionArguments);
}
} elseif ($element instanceof RuleSet) {
foreach ($element->getRules($searchString) as $oRule) {
$this->allValues($oRule, $result, $searchString, $searchInFunctionArguments);
foreach ($element->getRules($searchString) as $rule) {
$this->allValues($rule, $result, $searchString, $searchInFunctionArguments);
}
} elseif ($element instanceof Rule) {
$this->allValues($element->getValue(), $result, $searchString, $searchInFunctionArguments);
Expand Down
16 changes: 8 additions & 8 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ public function __construct($sRule, $lineNumber = 0, $iColNo = 0)
public static function parse(ParserState $parserState): Rule
{
$aComments = $parserState->consumeWhiteSpace();
$oRule = new Rule(
$rule = new Rule(
$parserState->parseIdentifier(!$parserState->comes('--')),
$parserState->currentLine(),
$parserState->currentColumn()
);
$oRule->setComments($aComments);
$oRule->addComments($parserState->consumeWhiteSpace());
$rule->setComments($aComments);
$rule->addComments($parserState->consumeWhiteSpace());
$parserState->consume(':');
$oValue = Value::parseValue($parserState, self::listDelimiterForRule($oRule->getRule()));
$oRule->setValue($oValue);
$oValue = Value::parseValue($parserState, self::listDelimiterForRule($rule->getRule()));
$rule->setValue($oValue);
if ($parserState->getSettings()->bLenientParsing) {
while ($parserState->comes('\\')) {
$parserState->consume('\\');
$oRule->addIeHack($parserState->consume());
$rule->addIeHack($parserState->consume());
$parserState->consumeWhiteSpace();
}
}
Expand All @@ -101,7 +101,7 @@ public static function parse(ParserState $parserState): Rule
$parserState->consume('!');
$parserState->consumeWhiteSpace();
$parserState->consume('important');
$oRule->setIsImportant(true);
$rule->setIsImportant(true);
}
$parserState->consumeWhiteSpace();
while ($parserState->comes(';')) {
Expand All @@ -110,7 +110,7 @@ public static function parse(ParserState $parserState): Rule

$parserState->consumeWhiteSpace();

return $oRule;
return $rule;
}

/**
Expand Down
44 changes: 22 additions & 22 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ public function __construct($lineNumber = 0)
* @throws UnexpectedTokenException
* @throws UnexpectedEOFException
*/
public static function parseRuleSet(ParserState $parserState, RuleSet $oRuleSet): void
public static function parseRuleSet(ParserState $parserState, RuleSet $ruleSet): void
{
while ($parserState->comes(';')) {
$parserState->consume(';');
}
while (!$parserState->comes('}')) {
$oRule = null;
$rule = null;
if ($parserState->getSettings()->bLenientParsing) {
try {
$oRule = Rule::parse($parserState);
$rule = Rule::parse($parserState);
} catch (UnexpectedTokenException $e) {
try {
$sConsume = $parserState->consumeUntil(["\n", ';', '}'], true);
Expand All @@ -80,10 +80,10 @@ public static function parseRuleSet(ParserState $parserState, RuleSet $oRuleSet)
}
}
} else {
$oRule = Rule::parse($parserState);
$rule = Rule::parse($parserState);
}
if ($oRule instanceof Rule) {
$oRuleSet->addRule($oRule);
if ($rule instanceof Rule) {
$ruleSet->addRule($rule);
}
}
$parserState->consume('}');
Expand All @@ -100,9 +100,9 @@ public function getLineNo()
/**
* @param Rule|null $oSibling
*/
public function addRule(Rule $oRule, ?Rule $oSibling = null): void
public function addRule(Rule $rule, ?Rule $oSibling = null): void
{
$sRule = $oRule->getRule();
$sRule = $rule->getRule();
if (!isset($this->aRules[$sRule])) {
$this->aRules[$sRule] = [];
}
Expand All @@ -113,28 +113,28 @@ public function addRule(Rule $oRule, ?Rule $oSibling = null): void
$iSiblingPos = \array_search($oSibling, $this->aRules[$sRule], true);
if ($iSiblingPos !== false) {
$iPosition = $iSiblingPos;
$oRule->setPosition($oSibling->getLineNo(), $oSibling->getColNo() - 1);
$rule->setPosition($oSibling->getLineNo(), $oSibling->getColNo() - 1);
}
}
if ($oRule->getLineNo() === 0 && $oRule->getColNo() === 0) {
if ($rule->getLineNo() === 0 && $rule->getColNo() === 0) {
//this node is added manually, give it the next best line
$rules = $this->getRules();
$pos = \count($rules);
if ($pos > 0) {
$last = $rules[$pos - 1];
$oRule->setPosition($last->getLineNo() + 1, 0);
$rule->setPosition($last->getLineNo() + 1, 0);
}
}

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

/**
* Returns all rules matching the given rule name
*
* @example $oRuleSet->getRules('font') // returns array(0 => $oRule, …) or array().
* @example $ruleSet->getRules('font') // returns array(0 => $rule, …) or array().
*
* @example $oRuleSet->getRules('font-')
* @example $ruleSet->getRules('font-')
* //returns an array of all rules either beginning with font- or matching font.
*
* @param Rule|string|null $mRule
Expand Down Expand Up @@ -206,8 +206,8 @@ public function getRulesAssoc($mRule = null)
{
/** @var array<string, Rule> $aResult */
$aResult = [];
foreach ($this->getRules($mRule) as $oRule) {
$aResult[$oRule->getRule()] = $oRule;
foreach ($this->getRules($mRule) as $rule) {
$aResult[$rule->getRule()] = $rule;
}
return $aResult;
}
Expand All @@ -219,7 +219,7 @@ public function getRulesAssoc($mRule = null)
* If given a name, it will remove all rules by that name.
*
* 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($oRule->getRule())`.
* remove all rules with the same name. To get the old behaviour, use `removeRule($rule->getRule())`.
*
* @param Rule|string|null $mRule
* pattern to remove. If $mRule is null, all rules are removed. If the pattern ends in a dash,
Expand All @@ -233,8 +233,8 @@ public function removeRule($mRule): void
if (!isset($this->aRules[$sRule])) {
return;
}
foreach ($this->aRules[$sRule] as $iKey => $oRule) {
if ($oRule === $mRule) {
foreach ($this->aRules[$sRule] as $iKey => $rule) {
if ($rule === $mRule) {
unset($this->aRules[$sRule][$iKey]);
}
}
Expand Down Expand Up @@ -268,9 +268,9 @@ protected function renderRules(OutputFormat $oOutputFormat)
$bIsFirst = true;
$oNextLevel = $oOutputFormat->nextLevel();
foreach ($this->aRules as $aRules) {
foreach ($aRules as $oRule) {
$sRendered = $oNextLevel->safely(function () use ($oRule, $oNextLevel) {
return $oRule->render($oNextLevel);
foreach ($aRules as $rule) {
$sRendered = $oNextLevel->safely(function () use ($rule, $oNextLevel) {
return $rule->render($oNextLevel);
});
if ($sRendered === null) {
continue;
Expand Down