Skip to content

Commit 48ecde4

Browse files
authored
[CLEANUP] Avoid Hungarian notation for oParserState (#834)
Part of #756
1 parent 9f5c7dc commit 48ecde4

File tree

14 files changed

+253
-253
lines changed

14 files changed

+253
-253
lines changed

src/CSSList/CSSList.php

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ public function __construct($lineNumber = 0)
6262
* @throws UnexpectedTokenException
6363
* @throws SourceException
6464
*/
65-
public static function parseList(ParserState $oParserState, CSSList $oList): void
65+
public static function parseList(ParserState $parserState, CSSList $oList): void
6666
{
6767
$bIsRoot = $oList instanceof Document;
68-
if (\is_string($oParserState)) {
69-
$oParserState = new ParserState($oParserState, Settings::create());
68+
if (\is_string($parserState)) {
69+
$parserState = new ParserState($parserState, Settings::create());
7070
}
71-
$bLenientParsing = $oParserState->getSettings()->bLenientParsing;
71+
$bLenientParsing = $parserState->getSettings()->bLenientParsing;
7272
$aComments = [];
73-
while (!$oParserState->isEnd()) {
74-
$aComments = \array_merge($aComments, $oParserState->consumeWhiteSpace());
73+
while (!$parserState->isEnd()) {
74+
$aComments = \array_merge($aComments, $parserState->consumeWhiteSpace());
7575
$oListItem = null;
7676
if ($bLenientParsing) {
7777
try {
78-
$oListItem = self::parseListItem($oParserState, $oList);
78+
$oListItem = self::parseListItem($parserState, $oList);
7979
} catch (UnexpectedTokenException $e) {
8080
$oListItem = false;
8181
}
8282
} else {
83-
$oListItem = self::parseListItem($oParserState, $oList);
83+
$oListItem = self::parseListItem($parserState, $oList);
8484
}
8585
if ($oListItem === null) {
8686
// List parsing finished
@@ -90,11 +90,11 @@ public static function parseList(ParserState $oParserState, CSSList $oList): voi
9090
$oListItem->addComments($aComments);
9191
$oList->append($oListItem);
9292
}
93-
$aComments = $oParserState->consumeWhiteSpace();
93+
$aComments = $parserState->consumeWhiteSpace();
9494
}
9595
$oList->addComments($aComments);
9696
if (!$bIsRoot && !$bLenientParsing) {
97-
throw new SourceException('Unexpected end of document', $oParserState->currentLine());
97+
throw new SourceException('Unexpected end of document', $parserState->currentLine());
9898
}
9999
}
100100

@@ -105,96 +105,96 @@ public static function parseList(ParserState $oParserState, CSSList $oList): voi
105105
* @throws UnexpectedEOFException
106106
* @throws UnexpectedTokenException
107107
*/
108-
private static function parseListItem(ParserState $oParserState, CSSList $oList)
108+
private static function parseListItem(ParserState $parserState, CSSList $oList)
109109
{
110110
$bIsRoot = $oList instanceof Document;
111-
if ($oParserState->comes('@')) {
112-
$oAtRule = self::parseAtRule($oParserState);
111+
if ($parserState->comes('@')) {
112+
$oAtRule = self::parseAtRule($parserState);
113113
if ($oAtRule instanceof Charset) {
114114
if (!$bIsRoot) {
115115
throw new UnexpectedTokenException(
116116
'@charset may only occur in root document',
117117
'',
118118
'custom',
119-
$oParserState->currentLine()
119+
$parserState->currentLine()
120120
);
121121
}
122122
if (\count($oList->getContents()) > 0) {
123123
throw new UnexpectedTokenException(
124124
'@charset must be the first parseable token in a document',
125125
'',
126126
'custom',
127-
$oParserState->currentLine()
127+
$parserState->currentLine()
128128
);
129129
}
130-
$oParserState->setCharset($oAtRule->getCharset());
130+
$parserState->setCharset($oAtRule->getCharset());
131131
}
132132
return $oAtRule;
133-
} elseif ($oParserState->comes('}')) {
133+
} elseif ($parserState->comes('}')) {
134134
if ($bIsRoot) {
135-
if ($oParserState->getSettings()->bLenientParsing) {
136-
return DeclarationBlock::parse($oParserState);
135+
if ($parserState->getSettings()->bLenientParsing) {
136+
return DeclarationBlock::parse($parserState);
137137
} else {
138-
throw new SourceException('Unopened {', $oParserState->currentLine());
138+
throw new SourceException('Unopened {', $parserState->currentLine());
139139
}
140140
} else {
141141
// End of list
142142
return null;
143143
}
144144
} else {
145-
return DeclarationBlock::parse($oParserState, $oList);
145+
return DeclarationBlock::parse($parserState, $oList);
146146
}
147147
}
148148

149149
/**
150-
* @param ParserState $oParserState
150+
* @param ParserState $parserState
151151
*
152152
* @return AtRuleBlockList|KeyFrame|Charset|CSSNamespace|Import|AtRuleSet|null
153153
*
154154
* @throws SourceException
155155
* @throws UnexpectedTokenException
156156
* @throws UnexpectedEOFException
157157
*/
158-
private static function parseAtRule(ParserState $oParserState)
158+
private static function parseAtRule(ParserState $parserState)
159159
{
160-
$oParserState->consume('@');
161-
$sIdentifier = $oParserState->parseIdentifier();
162-
$iIdentifierLineNum = $oParserState->currentLine();
163-
$oParserState->consumeWhiteSpace();
160+
$parserState->consume('@');
161+
$sIdentifier = $parserState->parseIdentifier();
162+
$iIdentifierLineNum = $parserState->currentLine();
163+
$parserState->consumeWhiteSpace();
164164
if ($sIdentifier === 'import') {
165-
$oLocation = URL::parse($oParserState);
166-
$oParserState->consumeWhiteSpace();
165+
$oLocation = URL::parse($parserState);
166+
$parserState->consumeWhiteSpace();
167167
$sMediaQuery = null;
168-
if (!$oParserState->comes(';')) {
169-
$sMediaQuery = \trim($oParserState->consumeUntil([';', ParserState::EOF]));
168+
if (!$parserState->comes(';')) {
169+
$sMediaQuery = \trim($parserState->consumeUntil([';', ParserState::EOF]));
170170
if ($sMediaQuery === '') {
171171
$sMediaQuery = null;
172172
}
173173
}
174-
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
174+
$parserState->consumeUntil([';', ParserState::EOF], true, true);
175175
return new Import($oLocation, $sMediaQuery, $iIdentifierLineNum);
176176
} elseif ($sIdentifier === 'charset') {
177-
$oCharsetString = CSSString::parse($oParserState);
178-
$oParserState->consumeWhiteSpace();
179-
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
177+
$oCharsetString = CSSString::parse($parserState);
178+
$parserState->consumeWhiteSpace();
179+
$parserState->consumeUntil([';', ParserState::EOF], true, true);
180180
return new Charset($oCharsetString, $iIdentifierLineNum);
181181
} elseif (self::identifierIs($sIdentifier, 'keyframes')) {
182182
$oResult = new KeyFrame($iIdentifierLineNum);
183183
$oResult->setVendorKeyFrame($sIdentifier);
184-
$oResult->setAnimationName(\trim($oParserState->consumeUntil('{', false, true)));
185-
CSSList::parseList($oParserState, $oResult);
186-
if ($oParserState->comes('}')) {
187-
$oParserState->consume('}');
184+
$oResult->setAnimationName(\trim($parserState->consumeUntil('{', false, true)));
185+
CSSList::parseList($parserState, $oResult);
186+
if ($parserState->comes('}')) {
187+
$parserState->consume('}');
188188
}
189189
return $oResult;
190190
} elseif ($sIdentifier === 'namespace') {
191191
$sPrefix = null;
192-
$mUrl = Value::parsePrimitiveValue($oParserState);
193-
if (!$oParserState->comes(';')) {
192+
$mUrl = Value::parsePrimitiveValue($parserState);
193+
if (!$parserState->comes(';')) {
194194
$sPrefix = $mUrl;
195-
$mUrl = Value::parsePrimitiveValue($oParserState);
195+
$mUrl = Value::parsePrimitiveValue($parserState);
196196
}
197-
$oParserState->consumeUntil([';', ParserState::EOF], true, true);
197+
$parserState->consumeUntil([';', ParserState::EOF], true, true);
198198
if ($sPrefix !== null && !\is_string($sPrefix)) {
199199
throw new UnexpectedTokenException('Wrong namespace prefix', $sPrefix, 'custom', $iIdentifierLineNum);
200200
}
@@ -209,12 +209,12 @@ private static function parseAtRule(ParserState $oParserState)
209209
return new CSSNamespace($mUrl, $sPrefix, $iIdentifierLineNum);
210210
} else {
211211
// Unknown other at rule (font-face or such)
212-
$sArgs = \trim($oParserState->consumeUntil('{', false, true));
212+
$sArgs = \trim($parserState->consumeUntil('{', false, true));
213213
if (\substr_count($sArgs, '(') != \substr_count($sArgs, ')')) {
214-
if ($oParserState->getSettings()->bLenientParsing) {
214+
if ($parserState->getSettings()->bLenientParsing) {
215215
return null;
216216
} else {
217-
throw new SourceException('Unmatched brace count in media query', $oParserState->currentLine());
217+
throw new SourceException('Unmatched brace count in media query', $parserState->currentLine());
218218
}
219219
}
220220
$bUseRuleSet = true;
@@ -226,12 +226,12 @@ private static function parseAtRule(ParserState $oParserState)
226226
}
227227
if ($bUseRuleSet) {
228228
$oAtRule = new AtRuleSet($sIdentifier, $sArgs, $iIdentifierLineNum);
229-
RuleSet::parseRuleSet($oParserState, $oAtRule);
229+
RuleSet::parseRuleSet($parserState, $oAtRule);
230230
} else {
231231
$oAtRule = new AtRuleBlockList($sIdentifier, $sArgs, $iIdentifierLineNum);
232-
CSSList::parseList($oParserState, $oAtRule);
233-
if ($oParserState->comes('}')) {
234-
$oParserState->consume('}');
232+
CSSList::parseList($parserState, $oAtRule);
233+
if ($parserState->comes('}')) {
234+
$parserState->consume('}');
235235
}
236236
}
237237
return $oAtRule;

src/CSSList/Document.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public function __construct($lineNumber = 0)
2929
/**
3030
* @throws SourceException
3131
*/
32-
public static function parse(ParserState $oParserState): Document
32+
public static function parse(ParserState $parserState): Document
3333
{
34-
$oDocument = new Document($oParserState->currentLine());
35-
CSSList::parseList($oParserState, $oDocument);
34+
$oDocument = new Document($parserState->currentLine());
35+
CSSList::parseList($parserState, $oDocument);
3636
return $oDocument;
3737
}
3838

src/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Parser
1616
/**
1717
* @var ParserState
1818
*/
19-
private $oParserState;
19+
private $parserState;
2020

2121
/**
2222
* @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
2828
if ($oParserSettings === null) {
2929
$oParserSettings = Settings::create();
3030
}
31-
$this->oParserState = new ParserState($sText, $oParserSettings, $lineNumber);
31+
$this->parserState = new ParserState($sText, $oParserSettings, $lineNumber);
3232
}
3333

3434
/**
@@ -38,6 +38,6 @@ public function __construct($sText, ?Settings $oParserSettings = null, $lineNumb
3838
*/
3939
public function parse(): Document
4040
{
41-
return Document::parse($this->oParserState);
41+
return Document::parse($this->parserState);
4242
}
4343
}

src/Parsing/Anchor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ class Anchor
1717
/**
1818
* @var ParserState
1919
*/
20-
private $oParserState;
20+
private $parserState;
2121

2222
/**
2323
* @param int $iPosition
2424
*/
25-
public function __construct($iPosition, ParserState $oParserState)
25+
public function __construct($iPosition, ParserState $parserState)
2626
{
2727
$this->iPosition = $iPosition;
28-
$this->oParserState = $oParserState;
28+
$this->parserState = $parserState;
2929
}
3030

3131
public function backtrack(): void
3232
{
33-
$this->oParserState->setPosition($this->iPosition);
33+
$this->parserState->setPosition($this->iPosition);
3434
}
3535
}

src/Rule/Rule.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,39 @@ public function __construct($sRule, $lineNumber = 0, $iColNo = 0)
7676
* @throws UnexpectedEOFException
7777
* @throws UnexpectedTokenException
7878
*/
79-
public static function parse(ParserState $oParserState): Rule
79+
public static function parse(ParserState $parserState): Rule
8080
{
81-
$aComments = $oParserState->consumeWhiteSpace();
81+
$aComments = $parserState->consumeWhiteSpace();
8282
$oRule = new Rule(
83-
$oParserState->parseIdentifier(!$oParserState->comes('--')),
84-
$oParserState->currentLine(),
85-
$oParserState->currentColumn()
83+
$parserState->parseIdentifier(!$parserState->comes('--')),
84+
$parserState->currentLine(),
85+
$parserState->currentColumn()
8686
);
8787
$oRule->setComments($aComments);
88-
$oRule->addComments($oParserState->consumeWhiteSpace());
89-
$oParserState->consume(':');
90-
$oValue = Value::parseValue($oParserState, self::listDelimiterForRule($oRule->getRule()));
88+
$oRule->addComments($parserState->consumeWhiteSpace());
89+
$parserState->consume(':');
90+
$oValue = Value::parseValue($parserState, self::listDelimiterForRule($oRule->getRule()));
9191
$oRule->setValue($oValue);
92-
if ($oParserState->getSettings()->bLenientParsing) {
93-
while ($oParserState->comes('\\')) {
94-
$oParserState->consume('\\');
95-
$oRule->addIeHack($oParserState->consume());
96-
$oParserState->consumeWhiteSpace();
92+
if ($parserState->getSettings()->bLenientParsing) {
93+
while ($parserState->comes('\\')) {
94+
$parserState->consume('\\');
95+
$oRule->addIeHack($parserState->consume());
96+
$parserState->consumeWhiteSpace();
9797
}
9898
}
99-
$oParserState->consumeWhiteSpace();
100-
if ($oParserState->comes('!')) {
101-
$oParserState->consume('!');
102-
$oParserState->consumeWhiteSpace();
103-
$oParserState->consume('important');
99+
$parserState->consumeWhiteSpace();
100+
if ($parserState->comes('!')) {
101+
$parserState->consume('!');
102+
$parserState->consumeWhiteSpace();
103+
$parserState->consume('important');
104104
$oRule->setIsImportant(true);
105105
}
106-
$oParserState->consumeWhiteSpace();
107-
while ($oParserState->comes(';')) {
108-
$oParserState->consume(';');
106+
$parserState->consumeWhiteSpace();
107+
while ($parserState->comes(';')) {
108+
$parserState->consume(';');
109109
}
110110

111-
$oParserState->consumeWhiteSpace();
111+
$parserState->consumeWhiteSpace();
112112

113113
return $oRule;
114114
}

src/RuleSet/DeclarationBlock.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,40 @@ public function __construct($lineNumber = 0)
5252
* @throws UnexpectedTokenException
5353
* @throws UnexpectedEOFException
5454
*/
55-
public static function parse(ParserState $oParserState, $oList = null)
55+
public static function parse(ParserState $parserState, $oList = null)
5656
{
5757
$aComments = [];
58-
$oResult = new DeclarationBlock($oParserState->currentLine());
58+
$oResult = new DeclarationBlock($parserState->currentLine());
5959
try {
6060
$aSelectorParts = [];
6161
$sStringWrapperChar = false;
6262
do {
63-
$aSelectorParts[] = $oParserState->consume(1)
64-
. $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
65-
if (\in_array($oParserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') {
63+
$aSelectorParts[] = $parserState->consume(1)
64+
. $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
65+
if (\in_array($parserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') {
6666
if ($sStringWrapperChar === false) {
67-
$sStringWrapperChar = $oParserState->peek();
68-
} elseif ($sStringWrapperChar == $oParserState->peek()) {
67+
$sStringWrapperChar = $parserState->peek();
68+
} elseif ($sStringWrapperChar == $parserState->peek()) {
6969
$sStringWrapperChar = false;
7070
}
7171
}
72-
} while (!\in_array($oParserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false);
72+
} while (!\in_array($parserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false);
7373
$oResult->setSelectors(\implode('', $aSelectorParts), $oList);
74-
if ($oParserState->comes('{')) {
75-
$oParserState->consume(1);
74+
if ($parserState->comes('{')) {
75+
$parserState->consume(1);
7676
}
7777
} catch (UnexpectedTokenException $e) {
78-
if ($oParserState->getSettings()->bLenientParsing) {
79-
if (!$oParserState->comes('}')) {
80-
$oParserState->consumeUntil('}', false, true);
78+
if ($parserState->getSettings()->bLenientParsing) {
79+
if (!$parserState->comes('}')) {
80+
$parserState->consumeUntil('}', false, true);
8181
}
8282
return false;
8383
} else {
8484
throw $e;
8585
}
8686
}
8787
$oResult->setComments($aComments);
88-
RuleSet::parseRuleSet($oParserState, $oResult);
88+
RuleSet::parseRuleSet($parserState, $oResult);
8989
return $oResult;
9090
}
9191

0 commit comments

Comments
 (0)