Skip to content

Commit 5d9902b

Browse files
committed
Merge branch 'patched-2024' into improvement/speed
2 parents 17aa3b8 + 0991001 commit 5d9902b

File tree

5 files changed

+16
-64
lines changed

5 files changed

+16
-64
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"codacy/coverage": "^1.4.3",
3131
"php-parallel-lint/php-parallel-lint": "^1.4.0",
3232
"phpstan/extension-installer": "^1.4.1",
33-
"phpstan/phpstan": "^1.11.7",
33+
"phpstan/phpstan": "^1.11.6",
3434
"phpstan/phpstan-phpunit": "^1.4.0",
3535
"phpunit/phpunit": "^8.5.38",
3636
"rector/rector": "^1.2.0"

config/php-cs-fixer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
// function notation
4343
'native_function_invocation' => ['include' => ['@all']],
44+
'nullable_type_declaration' => [
45+
'syntax' => 'question_mark',
46+
],
4447
'nullable_type_declaration_for_default_null_value' => true,
4548

4649
// import
@@ -51,7 +54,6 @@
5154
'combine_consecutive_unsets' => true,
5255
'dir_constant' => true,
5356
'is_null' => true,
54-
'nullable_type_declaration' => true,
5557

5658
// namespace notation
5759
'no_leading_namespace_whitespace' => true,

src/Value/CSSString.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
class CSSString extends PrimitiveValue
1717
{
18-
const PARSE_QUOTE_STRINGS = ['"', "'", '\"', "\'"];
19-
2018
/**
2119
* @var string
2220
*/
@@ -40,12 +38,11 @@ public function __construct($sString, $iLineNo = 0)
4038
public static function parse(ParserState $oParserState): CSSString
4139
{
4240
$sBegin = $oParserState->peek();
43-
if ($sBegin === '\\') {
44-
$sBegin = $oParserState->peek(2);
45-
}
4641
$sQuote = null;
47-
if (in_array($sBegin, self::PARSE_QUOTE_STRINGS)) {
48-
$sQuote = $sBegin;
42+
if ($sBegin === "'") {
43+
$sQuote = "'";
44+
} elseif ($sBegin === '"') {
45+
$sQuote = '"';
4946
}
5047
if ($sQuote !== null) {
5148
$oParserState->consume($sQuote);

src/Value/Value.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
*/
1515
abstract class Value implements Renderable
1616
{
17-
const PARSE_TERMINATE_STRINGS = ['}',';','!',')', '\\'];
18-
const PARSE_QUOTE_STRINGS = ['"', "'", '\"', "\'"];
19-
2017
/**
2118
* @var int
2219
*/
@@ -44,8 +41,13 @@ public static function parseValue(ParserState $oParserState, array $aListDelimit
4441
$aStack = [];
4542
$oParserState->consumeWhiteSpace();
4643
//Build a list of delimiters and parsed values
47-
while (self::continueParsing($oParserState)) {
48-
if (count($aStack) > 0) {
44+
while (
45+
!($oParserState->comes('}') || $oParserState->comes(';') || $oParserState->comes('!')
46+
|| $oParserState->comes(')')
47+
|| $oParserState->comes('\\')
48+
|| $oParserState->isEnd())
49+
) {
50+
if (\count($aStack) > 0) {
4951
$bFoundDelimiter = false;
5052
foreach ($aListDelimiters as $sDelimiter) {
5153
if ($oParserState->comes($sDelimiter)) {
@@ -154,10 +156,7 @@ public static function parsePrimitiveValue(ParserState $oParserState)
154156
$oValue = Size::parse($oParserState);
155157
} elseif ($oParserState->comes('#') || $oParserState->comes('rgb', true) || $oParserState->comes('hsl', true)) {
156158
$oValue = Color::parse($oParserState);
157-
} elseif (
158-
in_array($oParserState->peek(), self::PARSE_QUOTE_STRINGS)
159-
|| in_array($oParserState->peek(2), self::PARSE_QUOTE_STRINGS)
160-
) {
159+
} elseif ($oParserState->comes("'") || $oParserState->comes('"')) {
161160
$oValue = CSSString::parse($oParserState);
162161
} elseif ($oParserState->comes('progid:') && $oParserState->getSettings()->bLenientParsing) {
163162
$oValue = self::parseMicrosoftFilter($oParserState);
@@ -219,22 +218,4 @@ public function getLineNo()
219218
{
220219
return $this->iLineNo;
221220
}
222-
223-
/**
224-
* @return bool
225-
*
226-
* @throws UnexpectedEOFException
227-
* @throws UnexpectedTokenException
228-
*/
229-
private static function continueParsing(ParserState $oParserState)
230-
{
231-
if ($oParserState->isEnd()) {
232-
return false;
233-
}
234-
$sPeekOne = $oParserState->peek();
235-
if ($sPeekOne === '\\') {
236-
return in_array($oParserState->peek(2), self::PARSE_QUOTE_STRINGS);
237-
}
238-
return !in_array($sPeekOne, self::PARSE_TERMINATE_STRINGS);
239-
}
240221
}

tests/ParserTest.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,34 +1315,6 @@ public function infiniteLoopInFile(): void
13151315
self::assertSame($sExpected, $oDoc->render());
13161316
}
13171317

1318-
public function parseForEscapedQuotes(): void
1319-
{
1320-
$preParseCss = sprintf(
1321-
"%s%s%s%s%s%s%s",
1322-
'.fonts-first {font-family: Roboto, "Fira Mono", \"Liberation Serif\";}',
1323-
PHP_EOL,
1324-
".font-second {font-family: Roboto, 'Fira Mono', \'Liberation Serif\';}",
1325-
PHP_EOL,
1326-
'.bgpic-first {background-image: url(\"pic.webp\");}',
1327-
PHP_EOL,
1328-
".bgpic-second {background-image: url(\'pic.webp\');}"
1329-
);
1330-
$expectedCss = sprintf(
1331-
"%s%s%s%s%s%s%s",
1332-
'.fonts-first {font-family: Roboto,"Fira Mono","Liberation Serif";}',
1333-
PHP_EOL,
1334-
'.font-second {font-family: Roboto,"Fira Mono","Liberation Serif";}',
1335-
PHP_EOL,
1336-
'.bgpic-first {background-image: url("pic.webp");}',
1337-
PHP_EOL,
1338-
'.bgpic-second {background-image: url("pic.webp");}'
1339-
);
1340-
$parser = new Parser($preParseCss);
1341-
$document = $parser->parse();
1342-
$postParseCss = $document->render();
1343-
self::assertEquals($expectedCss, $postParseCss);
1344-
}
1345-
13461318
public function escapedSpecialCaseTokens(): void
13471319
{
13481320
$oDoc = $this->parsedStructureForFile('escaped-tokens');

0 commit comments

Comments
 (0)