From b06f903271e2a771770dc96d4d2f2a910da41af6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 27 Jan 2025 21:50:58 +0100 Subject: [PATCH] [CLEANUP] Avoid Hungarian notation for `oRule`/`oRuleSet` Part of #756 --- src/CSSList/CSSBlockList.php | 4 ++-- src/Rule/Rule.php | 16 ++++++------- src/RuleSet/RuleSet.php | 44 ++++++++++++++++++------------------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/CSSList/CSSBlockList.php b/src/CSSList/CSSBlockList.php index 137faff8..9a07293d 100644 --- a/src/CSSList/CSSBlockList.php +++ b/src/CSSList/CSSBlockList.php @@ -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); diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 8cdb05d7..f4033468 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -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(); } } @@ -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(';')) { @@ -110,7 +110,7 @@ public static function parse(ParserState $parserState): Rule $parserState->consumeWhiteSpace(); - return $oRule; + return $rule; } /** diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 71c86d1d..85184da3 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -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); @@ -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('}'); @@ -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] = []; } @@ -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 @@ -206,8 +206,8 @@ public function getRulesAssoc($mRule = null) { /** @var array $aResult */ $aResult = []; - foreach ($this->getRules($mRule) as $oRule) { - $aResult[$oRule->getRule()] = $oRule; + foreach ($this->getRules($mRule) as $rule) { + $aResult[$rule->getRule()] = $rule; } return $aResult; } @@ -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, @@ -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]); } } @@ -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;