Skip to content

[CLEANUP] Avoid Hungarian notation for oParserState #834

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
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
100 changes: 50 additions & 50 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}

Expand All @@ -105,96 +105,96 @@ 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) {
throw new UnexpectedTokenException(
'@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
*
* @throws SourceException
* @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);
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/CSSList/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
8 changes: 4 additions & 4 deletions src/Parsing/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
44 changes: 22 additions & 22 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
28 changes: 14 additions & 14 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,40 @@ 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 {
throw $e;
}
}
$oResult->setComments($aComments);
RuleSet::parseRuleSet($oParserState, $oResult);
RuleSet::parseRuleSet($parserState, $oResult);
return $oResult;
}

Expand Down
Loading