diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index d1c328c4..f91ff68d 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -62,25 +62,25 @@ public function __construct($lineNumber = 0) * @throws UnexpectedTokenException * @throws SourceException */ - public static function parseList(ParserState $oParserState, CSSList $oList): void + public static function parseList(ParserState $parserState, CSSList $oList): void { $bIsRoot = $oList instanceof Document; - if (\is_string($oParserState)) { - $oParserState = new ParserState($oParserState, Settings::create()); + if (\is_string($parserState)) { + $parserState = new ParserState($parserState, Settings::create()); } - $bLenientParsing = $oParserState->getSettings()->bLenientParsing; + $bLenientParsing = $parserState->getSettings()->bLenientParsing; $aComments = []; - while (!$oParserState->isEnd()) { - $aComments = \array_merge($aComments, $oParserState->consumeWhiteSpace()); + while (!$parserState->isEnd()) { + $aComments = \array_merge($aComments, $parserState->consumeWhiteSpace()); $oListItem = null; if ($bLenientParsing) { try { - $oListItem = self::parseListItem($oParserState, $oList); + $oListItem = self::parseListItem($parserState, $oList); } catch (UnexpectedTokenException $e) { $oListItem = false; } } else { - $oListItem = self::parseListItem($oParserState, $oList); + $oListItem = self::parseListItem($parserState, $oList); } if ($oListItem === null) { // List parsing finished @@ -90,11 +90,11 @@ public static function parseList(ParserState $oParserState, CSSList $oList): voi $oListItem->addComments($aComments); $oList->append($oListItem); } - $aComments = $oParserState->consumeWhiteSpace(); + $aComments = $parserState->consumeWhiteSpace(); } $oList->addComments($aComments); if (!$bIsRoot && !$bLenientParsing) { - throw new SourceException('Unexpected end of document', $oParserState->currentLine()); + throw new SourceException('Unexpected end of document', $parserState->currentLine()); } } @@ -105,18 +105,18 @@ public static function parseList(ParserState $oParserState, CSSList $oList): voi * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - private static function parseListItem(ParserState $oParserState, CSSList $oList) + private static function parseListItem(ParserState $parserState, CSSList $oList) { $bIsRoot = $oList instanceof Document; - if ($oParserState->comes('@')) { - $oAtRule = self::parseAtRule($oParserState); + if ($parserState->comes('@')) { + $oAtRule = self::parseAtRule($parserState); if ($oAtRule instanceof Charset) { if (!$bIsRoot) { throw new UnexpectedTokenException( '@charset may only occur in root document', '', 'custom', - $oParserState->currentLine() + $parserState->currentLine() ); } if (\count($oList->getContents()) > 0) { @@ -124,30 +124,30 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList) '@charset must be the first parseable token in a document', '', 'custom', - $oParserState->currentLine() + $parserState->currentLine() ); } - $oParserState->setCharset($oAtRule->getCharset()); + $parserState->setCharset($oAtRule->getCharset()); } return $oAtRule; - } elseif ($oParserState->comes('}')) { + } elseif ($parserState->comes('}')) { if ($bIsRoot) { - if ($oParserState->getSettings()->bLenientParsing) { - return DeclarationBlock::parse($oParserState); + if ($parserState->getSettings()->bLenientParsing) { + return DeclarationBlock::parse($parserState); } else { - throw new SourceException('Unopened {', $oParserState->currentLine()); + throw new SourceException('Unopened {', $parserState->currentLine()); } } else { // End of list return null; } } else { - return DeclarationBlock::parse($oParserState, $oList); + return DeclarationBlock::parse($parserState, $oList); } } /** - * @param ParserState $oParserState + * @param ParserState $parserState * * @return AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|null * @@ -155,46 +155,46 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList) * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - private static function parseAtRule(ParserState $oParserState) + private static function parseAtRule(ParserState $parserState) { - $oParserState->consume('@'); - $sIdentifier = $oParserState->parseIdentifier(); - $iIdentifierLineNum = $oParserState->currentLine(); - $oParserState->consumeWhiteSpace(); + $parserState->consume('@'); + $sIdentifier = $parserState->parseIdentifier(); + $iIdentifierLineNum = $parserState->currentLine(); + $parserState->consumeWhiteSpace(); if ($sIdentifier === 'import') { - $oLocation = URL::parse($oParserState); - $oParserState->consumeWhiteSpace(); + $oLocation = URL::parse($parserState); + $parserState->consumeWhiteSpace(); $sMediaQuery = null; - if (!$oParserState->comes(';')) { - $sMediaQuery = \trim($oParserState->consumeUntil([';', ParserState::EOF])); + if (!$parserState->comes(';')) { + $sMediaQuery = \trim($parserState->consumeUntil([';', ParserState::EOF])); if ($sMediaQuery === '') { $sMediaQuery = null; } } - $oParserState->consumeUntil([';', ParserState::EOF], true, true); + $parserState->consumeUntil([';', ParserState::EOF], true, true); return new Import($oLocation, $sMediaQuery, $iIdentifierLineNum); } elseif ($sIdentifier === 'charset') { - $oCharsetString = CSSString::parse($oParserState); - $oParserState->consumeWhiteSpace(); - $oParserState->consumeUntil([';', ParserState::EOF], true, true); + $oCharsetString = CSSString::parse($parserState); + $parserState->consumeWhiteSpace(); + $parserState->consumeUntil([';', ParserState::EOF], true, true); return new Charset($oCharsetString, $iIdentifierLineNum); } elseif (self::identifierIs($sIdentifier, 'keyframes')) { $oResult = new KeyFrame($iIdentifierLineNum); $oResult->setVendorKeyFrame($sIdentifier); - $oResult->setAnimationName(\trim($oParserState->consumeUntil('{', false, true))); - CSSList::parseList($oParserState, $oResult); - if ($oParserState->comes('}')) { - $oParserState->consume('}'); + $oResult->setAnimationName(\trim($parserState->consumeUntil('{', false, true))); + CSSList::parseList($parserState, $oResult); + if ($parserState->comes('}')) { + $parserState->consume('}'); } return $oResult; } elseif ($sIdentifier === 'namespace') { $sPrefix = null; - $mUrl = Value::parsePrimitiveValue($oParserState); - if (!$oParserState->comes(';')) { + $mUrl = Value::parsePrimitiveValue($parserState); + if (!$parserState->comes(';')) { $sPrefix = $mUrl; - $mUrl = Value::parsePrimitiveValue($oParserState); + $mUrl = Value::parsePrimitiveValue($parserState); } - $oParserState->consumeUntil([';', ParserState::EOF], true, true); + $parserState->consumeUntil([';', ParserState::EOF], true, true); if ($sPrefix !== null && !\is_string($sPrefix)) { throw new UnexpectedTokenException('Wrong namespace prefix', $sPrefix, 'custom', $iIdentifierLineNum); } @@ -209,12 +209,12 @@ private static function parseAtRule(ParserState $oParserState) return new CSSNamespace($mUrl, $sPrefix, $iIdentifierLineNum); } else { // Unknown other at rule (font-face or such) - $sArgs = \trim($oParserState->consumeUntil('{', false, true)); + $sArgs = \trim($parserState->consumeUntil('{', false, true)); if (\substr_count($sArgs, '(') != \substr_count($sArgs, ')')) { - if ($oParserState->getSettings()->bLenientParsing) { + if ($parserState->getSettings()->bLenientParsing) { return null; } else { - throw new SourceException('Unmatched brace count in media query', $oParserState->currentLine()); + throw new SourceException('Unmatched brace count in media query', $parserState->currentLine()); } } $bUseRuleSet = true; @@ -226,12 +226,12 @@ private static function parseAtRule(ParserState $oParserState) } if ($bUseRuleSet) { $oAtRule = new AtRuleSet($sIdentifier, $sArgs, $iIdentifierLineNum); - RuleSet::parseRuleSet($oParserState, $oAtRule); + RuleSet::parseRuleSet($parserState, $oAtRule); } else { $oAtRule = new AtRuleBlockList($sIdentifier, $sArgs, $iIdentifierLineNum); - CSSList::parseList($oParserState, $oAtRule); - if ($oParserState->comes('}')) { - $oParserState->consume('}'); + CSSList::parseList($parserState, $oAtRule); + if ($parserState->comes('}')) { + $parserState->consume('}'); } } return $oAtRule; diff --git a/src/CSSList/Document.php b/src/CSSList/Document.php index 7667587f..d577ffac 100644 --- a/src/CSSList/Document.php +++ b/src/CSSList/Document.php @@ -29,10 +29,10 @@ public function __construct($lineNumber = 0) /** * @throws SourceException */ - public static function parse(ParserState $oParserState): Document + public static function parse(ParserState $parserState): Document { - $oDocument = new Document($oParserState->currentLine()); - CSSList::parseList($oParserState, $oDocument); + $oDocument = new Document($parserState->currentLine()); + CSSList::parseList($parserState, $oDocument); return $oDocument; } diff --git a/src/Parser.php b/src/Parser.php index 2b09e507..9f9f4595 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -16,7 +16,7 @@ class Parser /** * @var ParserState */ - private $oParserState; + private $parserState; /** * @param string $sText the complete CSS as text (i.e., usually the contents of a CSS file) @@ -28,7 +28,7 @@ public function __construct($sText, ?Settings $oParserSettings = null, $lineNumb if ($oParserSettings === null) { $oParserSettings = Settings::create(); } - $this->oParserState = new ParserState($sText, $oParserSettings, $lineNumber); + $this->parserState = new ParserState($sText, $oParserSettings, $lineNumber); } /** @@ -38,6 +38,6 @@ public function __construct($sText, ?Settings $oParserSettings = null, $lineNumb */ public function parse(): Document { - return Document::parse($this->oParserState); + return Document::parse($this->parserState); } } diff --git a/src/Parsing/Anchor.php b/src/Parsing/Anchor.php index 545cb035..039f783e 100644 --- a/src/Parsing/Anchor.php +++ b/src/Parsing/Anchor.php @@ -17,19 +17,19 @@ class Anchor /** * @var ParserState */ - private $oParserState; + private $parserState; /** * @param int $iPosition */ - public function __construct($iPosition, ParserState $oParserState) + public function __construct($iPosition, ParserState $parserState) { $this->iPosition = $iPosition; - $this->oParserState = $oParserState; + $this->parserState = $parserState; } public function backtrack(): void { - $this->oParserState->setPosition($this->iPosition); + $this->parserState->setPosition($this->iPosition); } } diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 3f01a3fd..8cdb05d7 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -76,39 +76,39 @@ public function __construct($sRule, $lineNumber = 0, $iColNo = 0) * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState): Rule + public static function parse(ParserState $parserState): Rule { - $aComments = $oParserState->consumeWhiteSpace(); + $aComments = $parserState->consumeWhiteSpace(); $oRule = new Rule( - $oParserState->parseIdentifier(!$oParserState->comes('--')), - $oParserState->currentLine(), - $oParserState->currentColumn() + $parserState->parseIdentifier(!$parserState->comes('--')), + $parserState->currentLine(), + $parserState->currentColumn() ); $oRule->setComments($aComments); - $oRule->addComments($oParserState->consumeWhiteSpace()); - $oParserState->consume(':'); - $oValue = Value::parseValue($oParserState, self::listDelimiterForRule($oRule->getRule())); + $oRule->addComments($parserState->consumeWhiteSpace()); + $parserState->consume(':'); + $oValue = Value::parseValue($parserState, self::listDelimiterForRule($oRule->getRule())); $oRule->setValue($oValue); - if ($oParserState->getSettings()->bLenientParsing) { - while ($oParserState->comes('\\')) { - $oParserState->consume('\\'); - $oRule->addIeHack($oParserState->consume()); - $oParserState->consumeWhiteSpace(); + if ($parserState->getSettings()->bLenientParsing) { + while ($parserState->comes('\\')) { + $parserState->consume('\\'); + $oRule->addIeHack($parserState->consume()); + $parserState->consumeWhiteSpace(); } } - $oParserState->consumeWhiteSpace(); - if ($oParserState->comes('!')) { - $oParserState->consume('!'); - $oParserState->consumeWhiteSpace(); - $oParserState->consume('important'); + $parserState->consumeWhiteSpace(); + if ($parserState->comes('!')) { + $parserState->consume('!'); + $parserState->consumeWhiteSpace(); + $parserState->consume('important'); $oRule->setIsImportant(true); } - $oParserState->consumeWhiteSpace(); - while ($oParserState->comes(';')) { - $oParserState->consume(';'); + $parserState->consumeWhiteSpace(); + while ($parserState->comes(';')) { + $parserState->consume(';'); } - $oParserState->consumeWhiteSpace(); + $parserState->consumeWhiteSpace(); return $oRule; } diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index f4ce86bd..76ead48d 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -52,32 +52,32 @@ public function __construct($lineNumber = 0) * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parse(ParserState $oParserState, $oList = null) + public static function parse(ParserState $parserState, $oList = null) { $aComments = []; - $oResult = new DeclarationBlock($oParserState->currentLine()); + $oResult = new DeclarationBlock($parserState->currentLine()); try { $aSelectorParts = []; $sStringWrapperChar = false; do { - $aSelectorParts[] = $oParserState->consume(1) - . $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments); - if (\in_array($oParserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') { + $aSelectorParts[] = $parserState->consume(1) + . $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments); + if (\in_array($parserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') { if ($sStringWrapperChar === false) { - $sStringWrapperChar = $oParserState->peek(); - } elseif ($sStringWrapperChar == $oParserState->peek()) { + $sStringWrapperChar = $parserState->peek(); + } elseif ($sStringWrapperChar == $parserState->peek()) { $sStringWrapperChar = false; } } - } while (!\in_array($oParserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false); + } while (!\in_array($parserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false); $oResult->setSelectors(\implode('', $aSelectorParts), $oList); - if ($oParserState->comes('{')) { - $oParserState->consume(1); + if ($parserState->comes('{')) { + $parserState->consume(1); } } catch (UnexpectedTokenException $e) { - if ($oParserState->getSettings()->bLenientParsing) { - if (!$oParserState->comes('}')) { - $oParserState->consumeUntil('}', false, true); + if ($parserState->getSettings()->bLenientParsing) { + if (!$parserState->comes('}')) { + $parserState->consumeUntil('}', false, true); } return false; } else { @@ -85,7 +85,7 @@ public static function parse(ParserState $oParserState, $oList = null) } } $oResult->setComments($aComments); - RuleSet::parseRuleSet($oParserState, $oResult); + RuleSet::parseRuleSet($parserState, $oResult); return $oResult; } diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index b05b9c8a..71c86d1d 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -53,25 +53,25 @@ public function __construct($lineNumber = 0) * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parseRuleSet(ParserState $oParserState, RuleSet $oRuleSet): void + public static function parseRuleSet(ParserState $parserState, RuleSet $oRuleSet): void { - while ($oParserState->comes(';')) { - $oParserState->consume(';'); + while ($parserState->comes(';')) { + $parserState->consume(';'); } - while (!$oParserState->comes('}')) { + while (!$parserState->comes('}')) { $oRule = null; - if ($oParserState->getSettings()->bLenientParsing) { + if ($parserState->getSettings()->bLenientParsing) { try { - $oRule = Rule::parse($oParserState); + $oRule = Rule::parse($parserState); } catch (UnexpectedTokenException $e) { try { - $sConsume = $oParserState->consumeUntil(["\n", ';', '}'], true); + $sConsume = $parserState->consumeUntil(["\n", ';', '}'], true); // We need to “unfind” the matches to the end of the ruleSet as this will be matched later - if ($oParserState->streql(\substr($sConsume, -1), '}')) { - $oParserState->backtrack(1); + if ($parserState->streql(\substr($sConsume, -1), '}')) { + $parserState->backtrack(1); } else { - while ($oParserState->comes(';')) { - $oParserState->consume(';'); + while ($parserState->comes(';')) { + $parserState->consume(';'); } } } catch (UnexpectedTokenException $e) { @@ -80,13 +80,13 @@ public static function parseRuleSet(ParserState $oParserState, RuleSet $oRuleSet } } } else { - $oRule = Rule::parse($oParserState); + $oRule = Rule::parse($parserState); } if ($oRule instanceof Rule) { $oRuleSet->addRule($oRule); } } - $oParserState->consume('}'); + $parserState->consume('}'); } /** diff --git a/src/Value/CSSFunction.php b/src/Value/CSSFunction.php index 0cb3488b..ac0d14f1 100644 --- a/src/Value/CSSFunction.php +++ b/src/Value/CSSFunction.php @@ -40,14 +40,14 @@ public function __construct($sName, $aArguments, $sSeparator = ',', $lineNumber * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): CSSFunction + public static function parse(ParserState $parserState, bool $bIgnoreCase = false): CSSFunction { - $sName = self::parseName($oParserState, $bIgnoreCase); - $oParserState->consume('('); - $mArguments = self::parseArguments($oParserState); + $sName = self::parseName($parserState, $bIgnoreCase); + $parserState->consume('('); + $mArguments = self::parseArguments($parserState); - $oResult = new CSSFunction($sName, $mArguments, ',', $oParserState->currentLine()); - $oParserState->consume(')'); + $oResult = new CSSFunction($sName, $mArguments, ',', $parserState->currentLine()); + $parserState->consume(')'); return $oResult; } @@ -57,9 +57,9 @@ public static function parse(ParserState $oParserState, bool $bIgnoreCase = fals * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - private static function parseName(ParserState $oParserState, bool $bIgnoreCase = false): string + private static function parseName(ParserState $parserState, bool $bIgnoreCase = false): string { - return $oParserState->parseIdentifier($bIgnoreCase); + return $parserState->parseIdentifier($bIgnoreCase); } /** @@ -69,9 +69,9 @@ private static function parseName(ParserState $oParserState, bool $bIgnoreCase = * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - private static function parseArguments(ParserState $oParserState) + private static function parseArguments(ParserState $parserState) { - return Value::parseValue($oParserState, ['=', ' ', ',']); + return Value::parseValue($parserState, ['=', ' ', ',']); } /** diff --git a/src/Value/CSSString.php b/src/Value/CSSString.php index 64bd4091..a1ca1c70 100644 --- a/src/Value/CSSString.php +++ b/src/Value/CSSString.php @@ -37,9 +37,9 @@ public function __construct($sString, $lineNumber = 0) * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState): CSSString + public static function parse(ParserState $parserState): CSSString { - $sBegin = $oParserState->peek(); + $sBegin = $parserState->peek(); $sQuote = null; if ($sBegin === "'") { $sQuote = "'"; @@ -47,29 +47,29 @@ public static function parse(ParserState $oParserState): CSSString $sQuote = '"'; } if ($sQuote !== null) { - $oParserState->consume($sQuote); + $parserState->consume($sQuote); } $sResult = ''; $sContent = null; if ($sQuote === null) { // Unquoted strings end in whitespace or with braces, brackets, parentheses - while (\preg_match('/[\\s{}()<>\\[\\]]/isu', $oParserState->peek()) !== 1) { - $sResult .= $oParserState->parseCharacter(false); + while (\preg_match('/[\\s{}()<>\\[\\]]/isu', $parserState->peek()) !== 1) { + $sResult .= $parserState->parseCharacter(false); } } else { - while (!$oParserState->comes($sQuote)) { - $sContent = $oParserState->parseCharacter(false); + while (!$parserState->comes($sQuote)) { + $sContent = $parserState->parseCharacter(false); if ($sContent === null) { throw new SourceException( - "Non-well-formed quoted string {$oParserState->peek(3)}", - $oParserState->currentLine() + "Non-well-formed quoted string {$parserState->peek(3)}", + $parserState->currentLine() ); } $sResult .= $sContent; } - $oParserState->consume($sQuote); + $parserState->consume($sQuote); } - return new CSSString($sResult, $oParserState->currentLine()); + return new CSSString($sResult, $parserState->currentLine()); } /** diff --git a/src/Value/CalcFunction.php b/src/Value/CalcFunction.php index 0a7e8275..8288c7cd 100644 --- a/src/Value/CalcFunction.php +++ b/src/Value/CalcFunction.php @@ -24,80 +24,80 @@ class CalcFunction extends CSSFunction * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parse(ParserState $oParserState, bool $bIgnoreCase = false): CSSFunction + public static function parse(ParserState $parserState, bool $bIgnoreCase = false): CSSFunction { $aOperators = ['+', '-', '*', '/']; - $sFunction = $oParserState->parseIdentifier(); - if ($oParserState->peek() != '(') { + $sFunction = $parserState->parseIdentifier(); + if ($parserState->peek() != '(') { // Found ; or end of line before an opening bracket - throw new UnexpectedTokenException('(', $oParserState->peek(), 'literal', $oParserState->currentLine()); + throw new UnexpectedTokenException('(', $parserState->peek(), 'literal', $parserState->currentLine()); } elseif (!\in_array($sFunction, ['calc', '-moz-calc', '-webkit-calc'], true)) { // Found invalid calc definition. Example calc (... - throw new UnexpectedTokenException('calc', $sFunction, 'literal', $oParserState->currentLine()); + throw new UnexpectedTokenException('calc', $sFunction, 'literal', $parserState->currentLine()); } - $oParserState->consume('('); - $oCalcList = new CalcRuleValueList($oParserState->currentLine()); - $oList = new RuleValueList(',', $oParserState->currentLine()); + $parserState->consume('('); + $oCalcList = new CalcRuleValueList($parserState->currentLine()); + $oList = new RuleValueList(',', $parserState->currentLine()); $iNestingLevel = 0; $iLastComponentType = null; - while (!$oParserState->comes(')') || $iNestingLevel > 0) { - if ($oParserState->isEnd() && $iNestingLevel === 0) { + while (!$parserState->comes(')') || $iNestingLevel > 0) { + if ($parserState->isEnd() && $iNestingLevel === 0) { break; } - $oParserState->consumeWhiteSpace(); - if ($oParserState->comes('(')) { + $parserState->consumeWhiteSpace(); + if ($parserState->comes('(')) { $iNestingLevel++; - $oCalcList->addListComponent($oParserState->consume(1)); - $oParserState->consumeWhiteSpace(); + $oCalcList->addListComponent($parserState->consume(1)); + $parserState->consumeWhiteSpace(); continue; - } elseif ($oParserState->comes(')')) { + } elseif ($parserState->comes(')')) { $iNestingLevel--; - $oCalcList->addListComponent($oParserState->consume(1)); - $oParserState->consumeWhiteSpace(); + $oCalcList->addListComponent($parserState->consume(1)); + $parserState->consumeWhiteSpace(); continue; } if ($iLastComponentType != CalcFunction::T_OPERAND) { - $oVal = Value::parsePrimitiveValue($oParserState); + $oVal = Value::parsePrimitiveValue($parserState); $oCalcList->addListComponent($oVal); $iLastComponentType = CalcFunction::T_OPERAND; } else { - if (\in_array($oParserState->peek(), $aOperators, true)) { - if (($oParserState->comes('-') || $oParserState->comes('+'))) { + if (\in_array($parserState->peek(), $aOperators, true)) { + if (($parserState->comes('-') || $parserState->comes('+'))) { if ( - $oParserState->peek(1, -1) != ' ' - || !($oParserState->comes('- ') - || $oParserState->comes('+ ')) + $parserState->peek(1, -1) != ' ' + || !($parserState->comes('- ') + || $parserState->comes('+ ')) ) { throw new UnexpectedTokenException( - " {$oParserState->peek()} ", - $oParserState->peek(1, -1) . $oParserState->peek(2), + " {$parserState->peek()} ", + $parserState->peek(1, -1) . $parserState->peek(2), 'literal', - $oParserState->currentLine() + $parserState->currentLine() ); } } - $oCalcList->addListComponent($oParserState->consume(1)); + $oCalcList->addListComponent($parserState->consume(1)); $iLastComponentType = CalcFunction::T_OPERATOR; } else { throw new UnexpectedTokenException( \sprintf( 'Next token was expected to be an operand of type %s. Instead "%s" was found.', \implode(', ', $aOperators), - $oParserState->peek() + $parserState->peek() ), '', 'custom', - $oParserState->currentLine() + $parserState->currentLine() ); } } - $oParserState->consumeWhiteSpace(); + $parserState->consumeWhiteSpace(); } $oList->addListComponent($oCalcList); - if (!$oParserState->isEnd()) { - $oParserState->consume(')'); + if (!$parserState->isEnd()) { + $parserState->consume(')'); } - return new CalcFunction($sFunction, $oList, ',', $oParserState->currentLine()); + return new CalcFunction($sFunction, $oList, ',', $parserState->currentLine()); } } diff --git a/src/Value/LineName.php b/src/Value/LineName.php index 9011acad..18a53333 100644 --- a/src/Value/LineName.php +++ b/src/Value/LineName.php @@ -24,27 +24,27 @@ public function __construct(array $aComponents = [], $lineNumber = 0) * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parse(ParserState $oParserState): LineName + public static function parse(ParserState $parserState): LineName { - $oParserState->consume('['); - $oParserState->consumeWhiteSpace(); + $parserState->consume('['); + $parserState->consumeWhiteSpace(); $aNames = []; do { - if ($oParserState->getSettings()->bLenientParsing) { + if ($parserState->getSettings()->bLenientParsing) { try { - $aNames[] = $oParserState->parseIdentifier(); + $aNames[] = $parserState->parseIdentifier(); } catch (UnexpectedTokenException $e) { - if (!$oParserState->comes(']')) { + if (!$parserState->comes(']')) { throw $e; } } } else { - $aNames[] = $oParserState->parseIdentifier(); + $aNames[] = $parserState->parseIdentifier(); } - $oParserState->consumeWhiteSpace(); - } while (!$oParserState->comes(']')); - $oParserState->consume(']'); - return new LineName($aNames, $oParserState->currentLine()); + $parserState->consumeWhiteSpace(); + } while (!$parserState->comes(']')); + $parserState->consume(']'); + return new LineName($aNames, $parserState->currentLine()); } public function __toString(): string diff --git a/src/Value/Size.php b/src/Value/Size.php index bf7ce6b8..82fdc261 100644 --- a/src/Value/Size.php +++ b/src/Value/Size.php @@ -87,39 +87,39 @@ public function __construct($fSize, $sUnit = null, $bIsColorComponent = false, $ * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState, $bIsColorComponent = false): Size + public static function parse(ParserState $parserState, $bIsColorComponent = false): Size { $sSize = ''; - if ($oParserState->comes('-')) { - $sSize .= $oParserState->consume('-'); + if ($parserState->comes('-')) { + $sSize .= $parserState->consume('-'); } - while (\is_numeric($oParserState->peek()) || $oParserState->comes('.') || $oParserState->comes('e', true)) { - if ($oParserState->comes('.')) { - $sSize .= $oParserState->consume('.'); - } elseif ($oParserState->comes('e', true)) { - $sLookahead = $oParserState->peek(1, 1); + while (\is_numeric($parserState->peek()) || $parserState->comes('.') || $parserState->comes('e', true)) { + if ($parserState->comes('.')) { + $sSize .= $parserState->consume('.'); + } elseif ($parserState->comes('e', true)) { + $sLookahead = $parserState->peek(1, 1); if (\is_numeric($sLookahead) || $sLookahead === '+' || $sLookahead === '-') { - $sSize .= $oParserState->consume(2); + $sSize .= $parserState->consume(2); } else { break; // Reached the unit part of the number like "em" or "ex" } } else { - $sSize .= $oParserState->consume(1); + $sSize .= $parserState->consume(1); } } $sUnit = null; $aSizeUnits = self::getSizeUnits(); foreach ($aSizeUnits as $iLength => &$aValues) { - $sKey = \strtolower($oParserState->peek($iLength)); + $sKey = \strtolower($parserState->peek($iLength)); if (\array_key_exists($sKey, $aValues)) { if (($sUnit = $aValues[$sKey]) !== null) { - $oParserState->consume($iLength); + $parserState->consume($iLength); break; } } } - return new Size((float) $sSize, $sUnit, $bIsColorComponent, $oParserState->currentLine()); + return new Size((float) $sSize, $sUnit, $bIsColorComponent, $parserState->currentLine()); } /** diff --git a/src/Value/URL.php b/src/Value/URL.php index ef180eab..cefaef53 100644 --- a/src/Value/URL.php +++ b/src/Value/URL.php @@ -34,29 +34,29 @@ public function __construct(CSSString $oURL, $lineNumber = 0) * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parse(ParserState $oParserState): URL + public static function parse(ParserState $parserState): URL { - $oAnchor = $oParserState->anchor(); + $oAnchor = $parserState->anchor(); $sIdentifier = ''; for ($i = 0; $i < 3; $i++) { - $sChar = $oParserState->parseCharacter(true); + $sChar = $parserState->parseCharacter(true); if ($sChar === null) { break; } $sIdentifier .= $sChar; } - $bUseUrl = $oParserState->streql($sIdentifier, 'url'); + $bUseUrl = $parserState->streql($sIdentifier, 'url'); if ($bUseUrl) { - $oParserState->consumeWhiteSpace(); - $oParserState->consume('('); + $parserState->consumeWhiteSpace(); + $parserState->consume('('); } else { $oAnchor->backtrack(); } - $oParserState->consumeWhiteSpace(); - $oResult = new URL(CSSString::parse($oParserState), $oParserState->currentLine()); + $parserState->consumeWhiteSpace(); + $oResult = new URL(CSSString::parse($parserState), $parserState->currentLine()); if ($bUseUrl) { - $oParserState->consumeWhiteSpace(); - $oParserState->consume(')'); + $parserState->consumeWhiteSpace(); + $parserState->consume(')'); } return $oResult; } diff --git a/src/Value/Value.php b/src/Value/Value.php index 9c8ad164..b11c1085 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -37,24 +37,24 @@ public function __construct($lineNumber = 0) * @throws UnexpectedTokenException * @throws UnexpectedEOFException */ - public static function parseValue(ParserState $oParserState, array $aListDelimiters = []) + public static function parseValue(ParserState $parserState, array $aListDelimiters = []) { /** @var array $aStack */ $aStack = []; - $oParserState->consumeWhiteSpace(); + $parserState->consumeWhiteSpace(); //Build a list of delimiters and parsed values while ( - !($oParserState->comes('}') || $oParserState->comes(';') || $oParserState->comes('!') - || $oParserState->comes(')') - || $oParserState->comes('\\') - || $oParserState->isEnd()) + !($parserState->comes('}') || $parserState->comes(';') || $parserState->comes('!') + || $parserState->comes(')') + || $parserState->comes('\\') + || $parserState->isEnd()) ) { if (\count($aStack) > 0) { $bFoundDelimiter = false; foreach ($aListDelimiters as $sDelimiter) { - if ($oParserState->comes($sDelimiter)) { - \array_push($aStack, $oParserState->consume($sDelimiter)); - $oParserState->consumeWhiteSpace(); + if ($parserState->comes($sDelimiter)) { + \array_push($aStack, $parserState->consume($sDelimiter)); + $parserState->consumeWhiteSpace(); $bFoundDelimiter = true; break; } @@ -64,8 +64,8 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit \array_push($aStack, ' '); } } - \array_push($aStack, self::parsePrimitiveValue($oParserState)); - $oParserState->consumeWhiteSpace(); + \array_push($aStack, self::parsePrimitiveValue($parserState)); + $parserState->consumeWhiteSpace(); } // Convert the list to list objects foreach ($aListDelimiters as $sDelimiter) { @@ -85,7 +85,7 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit break; } } - $oList = new RuleValueList($sDelimiter, $oParserState->currentLine()); + $oList = new RuleValueList($sDelimiter, $parserState->currentLine()); for ($i = $iStartPosition; $i - $iStartPosition < $iLength * 2; $i += 2) { $oList->addListComponent($aStack[$i]); } @@ -96,10 +96,10 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit } if (!isset($aStack[0])) { throw new UnexpectedTokenException( - " {$oParserState->peek()} ", - $oParserState->peek(1, -1) . $oParserState->peek(2), + " {$parserState->peek()} ", + $parserState->peek(1, -1) . $parserState->peek(2), 'literal', - $oParserState->currentLine() + $parserState->currentLine() ); } return $aStack[0]; @@ -113,23 +113,23 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - public static function parseIdentifierOrFunction(ParserState $oParserState, $bIgnoreCase = false) + public static function parseIdentifierOrFunction(ParserState $parserState, $bIgnoreCase = false) { - $oAnchor = $oParserState->anchor(); - $mResult = $oParserState->parseIdentifier($bIgnoreCase); + $oAnchor = $parserState->anchor(); + $mResult = $parserState->parseIdentifier($bIgnoreCase); - if ($oParserState->comes('(')) { + if ($parserState->comes('(')) { $oAnchor->backtrack(); - if ($oParserState->streql('url', $mResult)) { - $mResult = URL::parse($oParserState); + if ($parserState->streql('url', $mResult)) { + $mResult = URL::parse($parserState); } elseif ( - $oParserState->streql('calc', $mResult) - || $oParserState->streql('-webkit-calc', $mResult) - || $oParserState->streql('-moz-calc', $mResult) + $parserState->streql('calc', $mResult) + || $parserState->streql('-webkit-calc', $mResult) + || $parserState->streql('-moz-calc', $mResult) ) { - $mResult = CalcFunction::parse($oParserState); + $mResult = CalcFunction::parse($parserState); } else { - $mResult = CSSFunction::parse($oParserState, $bIgnoreCase); + $mResult = CSSFunction::parse($parserState, $bIgnoreCase); } } @@ -143,40 +143,40 @@ public static function parseIdentifierOrFunction(ParserState $oParserState, $bIg * @throws UnexpectedTokenException * @throws SourceException */ - public static function parsePrimitiveValue(ParserState $oParserState) + public static function parsePrimitiveValue(ParserState $parserState) { $oValue = null; - $oParserState->consumeWhiteSpace(); + $parserState->consumeWhiteSpace(); if ( - \is_numeric($oParserState->peek()) - || ($oParserState->comes('-.') - && \is_numeric($oParserState->peek(1, 2))) - || (($oParserState->comes('-') || $oParserState->comes('.')) && \is_numeric($oParserState->peek(1, 1))) + \is_numeric($parserState->peek()) + || ($parserState->comes('-.') + && \is_numeric($parserState->peek(1, 2))) + || (($parserState->comes('-') || $parserState->comes('.')) && \is_numeric($parserState->peek(1, 1))) ) { - $oValue = Size::parse($oParserState); - } elseif ($oParserState->comes('#') || $oParserState->comes('rgb', true) || $oParserState->comes('hsl', true)) { - $oValue = Color::parse($oParserState); - } elseif ($oParserState->comes("'") || $oParserState->comes('"')) { - $oValue = CSSString::parse($oParserState); - } elseif ($oParserState->comes('progid:') && $oParserState->getSettings()->bLenientParsing) { - $oValue = self::parseMicrosoftFilter($oParserState); - } elseif ($oParserState->comes('[')) { - $oValue = LineName::parse($oParserState); - } elseif ($oParserState->comes('U+')) { - $oValue = self::parseUnicodeRangeValue($oParserState); + $oValue = Size::parse($parserState); + } elseif ($parserState->comes('#') || $parserState->comes('rgb', true) || $parserState->comes('hsl', true)) { + $oValue = Color::parse($parserState); + } elseif ($parserState->comes("'") || $parserState->comes('"')) { + $oValue = CSSString::parse($parserState); + } elseif ($parserState->comes('progid:') && $parserState->getSettings()->bLenientParsing) { + $oValue = self::parseMicrosoftFilter($parserState); + } elseif ($parserState->comes('[')) { + $oValue = LineName::parse($parserState); + } elseif ($parserState->comes('U+')) { + $oValue = self::parseUnicodeRangeValue($parserState); } else { - $sNextChar = $oParserState->peek(1); + $sNextChar = $parserState->peek(1); try { - $oValue = self::parseIdentifierOrFunction($oParserState); + $oValue = self::parseIdentifierOrFunction($parserState); } catch (UnexpectedTokenException $e) { if (\in_array($sNextChar, ['+', '-', '*', '/'], true)) { - $oValue = $oParserState->consume(1); + $oValue = $parserState->consume(1); } else { throw $e; } } } - $oParserState->consumeWhiteSpace(); + $parserState->consumeWhiteSpace(); return $oValue; } @@ -184,28 +184,28 @@ public static function parsePrimitiveValue(ParserState $oParserState) * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - private static function parseMicrosoftFilter(ParserState $oParserState): CSSFunction + private static function parseMicrosoftFilter(ParserState $parserState): CSSFunction { - $sFunction = $oParserState->consumeUntil('(', false, true); - $aArguments = Value::parseValue($oParserState, [',', '=']); - return new CSSFunction($sFunction, $aArguments, ',', $oParserState->currentLine()); + $sFunction = $parserState->consumeUntil('(', false, true); + $aArguments = Value::parseValue($parserState, [',', '=']); + return new CSSFunction($sFunction, $aArguments, ',', $parserState->currentLine()); } /** * @throws UnexpectedEOFException * @throws UnexpectedTokenException */ - private static function parseUnicodeRangeValue(ParserState $oParserState): string + private static function parseUnicodeRangeValue(ParserState $parserState): string { $iCodepointMaxLength = 6; // Code points outside BMP can use up to six digits $sRange = ''; - $oParserState->consume('U+'); + $parserState->consume('U+'); do { - if ($oParserState->comes('-')) { + if ($parserState->comes('-')) { $iCodepointMaxLength = 13; // Max length is 2 six-digit code points + the dash(-) between them } - $sRange .= $oParserState->consume(1); - } while (\strlen($sRange) < $iCodepointMaxLength && \preg_match('/[A-Fa-f0-9\\?-]/', $oParserState->peek())); + $sRange .= $parserState->consume(1); + } while (\strlen($sRange) < $iCodepointMaxLength && \preg_match('/[A-Fa-f0-9\\?-]/', $parserState->peek())); return "U+{$sRange}"; }