Skip to content

Commit a28ad75

Browse files
authored
[CLEANUP] Use single-quoted string literals whenever possible (MyIntervals#642)
Fixes MyIntervals#640
1 parent fdcf59d commit a28ad75

14 files changed

+51
-50
lines changed

config/php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
'strict_param' => true,
9393

9494
// string notation
95+
'single_quote' => true,
9596
'string_implicit_backslashes' => ['single_quoted' => 'escape'],
9697
]
9798
);

src/CSSList/CSSList.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static function parseList(ParserState $oParserState, CSSList $oList): voi
9292
}
9393
$oList->addComments($aComments);
9494
if (!$bIsRoot && !$bLenientParsing) {
95-
throw new SourceException("Unexpected end of document", $oParserState->currentLine());
95+
throw new SourceException('Unexpected end of document', $oParserState->currentLine());
9696
}
9797
}
9898

@@ -133,7 +133,7 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList)
133133
if ($oParserState->getSettings()->bLenientParsing) {
134134
return DeclarationBlock::parse($oParserState);
135135
} else {
136-
throw new SourceException("Unopened {", $oParserState->currentLine());
136+
throw new SourceException('Unopened {', $oParserState->currentLine());
137137
}
138138
} else {
139139
// End of list
@@ -205,11 +205,11 @@ private static function parseAtRule(ParserState $oParserState)
205205
} else {
206206
// Unknown other at rule (font-face or such)
207207
$sArgs = \trim($oParserState->consumeUntil('{', false, true));
208-
if (\substr_count($sArgs, "(") != \substr_count($sArgs, ")")) {
208+
if (\substr_count($sArgs, '(') != \substr_count($sArgs, ')')) {
209209
if ($oParserState->getSettings()->bLenientParsing) {
210210
return null;
211211
} else {
212-
throw new SourceException("Unmatched brace count in media query", $oParserState->currentLine());
212+
throw new SourceException('Unmatched brace count in media query', $oParserState->currentLine());
213213
}
214214
}
215215
$bUseRuleSet = true;
@@ -375,7 +375,7 @@ public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false
375375
throw new UnexpectedTokenException(
376376
"Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.",
377377
$mSel,
378-
"custom"
378+
'custom'
379379
);
380380
}
381381
$mSel = new Selector($mSel);

src/OutputFormat.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function indentWithTabs($iNumber = 1)
258258
*/
259259
public function indentWithSpaces($iNumber = 2)
260260
{
261-
return $this->setIndentation(\str_repeat(" ", $iNumber));
261+
return $this->setIndentation(\str_repeat(' ', $iNumber));
262262
}
263263

264264
/**
@@ -314,8 +314,8 @@ public static function create(): OutputFormat
314314
public static function createCompact()
315315
{
316316
$format = self::create();
317-
$format->set('Space*Rules', "")
318-
->set('Space*Blocks', "")
317+
$format->set('Space*Rules', '')
318+
->set('Space*Blocks', '')
319319
->setSpaceAfterRuleName('')
320320
->setSpaceBeforeOpeningBrace('')
321321
->setSpaceAfterSelectorSeparator('')

src/Parsing/ParserState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function parseCharacter($bIsForIdentifier)
193193
}
194194
}
195195
$iUnicode = \intval($sUnicode, 16);
196-
$sUtf32 = "";
196+
$sUtf32 = '';
197197
for ($i = 0; $i < 4; ++$i) {
198198
$sUtf32 .= \chr($iUnicode & 0xff);
199199
$iUnicode = $iUnicode >> 8;

src/Property/Import.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __toString(): string
7575

7676
public function render(OutputFormat $oOutputFormat): string
7777
{
78-
return $oOutputFormat->comments($this) . "@import " . $this->oLocation->render($oOutputFormat)
78+
return $oOutputFormat->comments($this) . '@import ' . $this->oLocation->render($oOutputFormat)
7979
. ($this->sMediaQuery === null ? '' : ' ' . $this->sMediaQuery) . ';';
8080
}
8181

src/Rule/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function parse(ParserState $oParserState): Rule
7878
{
7979
$aComments = $oParserState->consumeWhiteSpace();
8080
$oRule = new Rule(
81-
$oParserState->parseIdentifier(!$oParserState->comes("--")),
81+
$oParserState->parseIdentifier(!$oParserState->comes('--')),
8282
$oParserState->currentLine(),
8383
$oParserState->currentColumn()
8484
);

src/RuleSet/DeclarationBlock.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function parse(ParserState $oParserState, $oList = null)
6060
do {
6161
$aSelectorParts[] = $oParserState->consume(1)
6262
. $oParserState->consumeUntil(['{', '}', '\'', '"'], false, false, $aComments);
63-
if (\in_array($oParserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != "\\") {
63+
if (\in_array($oParserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') {
6464
if ($sStringWrapperChar === false) {
6565
$sStringWrapperChar = $oParserState->peek();
6666
} elseif ($sStringWrapperChar == $oParserState->peek()) {
@@ -107,7 +107,7 @@ public function setSelectors($mSelector, $oList = null): void
107107
throw new UnexpectedTokenException(
108108
"Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.",
109109
$mSelector,
110-
"custom"
110+
'custom'
111111
);
112112
}
113113
$this->aSelectors[$iKey] = new Selector($mSelector);
@@ -116,7 +116,7 @@ public function setSelectors($mSelector, $oList = null): void
116116
throw new UnexpectedTokenException(
117117
"Selector did not match '" . KeyframeSelector::SELECTOR_VALIDATION_RX . "'.",
118118
$mSelector,
119-
"custom"
119+
'custom'
120120
);
121121
}
122122
$this->aSelectors[$iKey] = new KeyframeSelector($mSelector);
@@ -225,14 +225,14 @@ public function expandBorderShorthand(): void
225225
$mNewValue = $mValue;
226226
}
227227
if ($mValue instanceof Size) {
228-
$sNewRuleName = $sBorderRule . "-width";
228+
$sNewRuleName = $sBorderRule . '-width';
229229
} elseif ($mValue instanceof Color) {
230-
$sNewRuleName = $sBorderRule . "-color";
230+
$sNewRuleName = $sBorderRule . '-color';
231231
} else {
232232
if (\in_array($mValue, $aBorderSizes, true)) {
233-
$sNewRuleName = $sBorderRule . "-width";
233+
$sNewRuleName = $sBorderRule . '-width';
234234
} else {
235-
$sNewRuleName = $sBorderRule . "-style";
235+
$sNewRuleName = $sBorderRule . '-style';
236236
}
237237
}
238238
$oNewRule = new Rule($sNewRuleName, $oRule->getLineNo(), $oRule->getColNo());
@@ -789,7 +789,7 @@ public function render(OutputFormat $oOutputFormat): string
789789
$sResult = $oOutputFormat->comments($this);
790790
if (\count($this->aSelectors) === 0) {
791791
// If all the selectors have been removed, this declaration block becomes invalid
792-
throw new OutputException("Attempt to print declaration block with missing selector", $this->iLineNo);
792+
throw new OutputException('Attempt to print declaration block with missing selector', $this->iLineNo);
793793
}
794794
$sResult .= $oOutputFormat->sBeforeDeclarationBlock;
795795
$sResult .= $oOutputFormat->implode(

src/RuleSet/RuleSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function parseRuleSet(ParserState $oParserState, RuleSet $oRuleSet
6363
$oRule = Rule::parse($oParserState);
6464
} catch (UnexpectedTokenException $e) {
6565
try {
66-
$sConsume = $oParserState->consumeUntil(["\n", ";", '}'], true);
66+
$sConsume = $oParserState->consumeUntil(["\n", ';', '}'], true);
6767
// We need to “unfind” the matches to the end of the ruleSet as this will be matched later
6868
if ($oParserState->streql(\substr($sConsume, -1), '}')) {
6969
$oParserState->backtrack(1);

src/Value/CSSString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function parse(ParserState $oParserState): CSSString
4747
if ($sQuote !== null) {
4848
$oParserState->consume($sQuote);
4949
}
50-
$sResult = "";
50+
$sResult = '';
5151
$sContent = null;
5252
if ($sQuote === null) {
5353
// Unquoted strings end in whitespace or with braces, brackets, parentheses

src/Value/Size.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ public function render(OutputFormat $oOutputFormat): string
203203
{
204204
$l = \localeconv();
205205
$sPoint = \preg_quote($l['decimal_point'], '/');
206-
$sSize = \preg_match("/[\\d\\.]+e[+-]?\\d+/i", (string) $this->fSize)
207-
? \preg_replace("/$sPoint?0+$/", "", \sprintf("%f", $this->fSize)) : $this->fSize;
208-
return \preg_replace(["/$sPoint/", "/^(-?)0\\./"], ['.', '$1.'], $sSize)
206+
$sSize = \preg_match('/[\\d\\.]+e[+-]?\\d+/i', (string) $this->fSize)
207+
? \preg_replace("/$sPoint?0+$/", '', \sprintf('%f', $this->fSize)) : $this->fSize;
208+
return \preg_replace(["/$sPoint/", '/^(-?)0\\./'], ['.', '$1.'], $sSize)
209209
. ($this->sUnit ?? '');
210210
}
211211
}

src/Value/Value.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ public static function parsePrimitiveValue(ParserState $oParserState)
156156
$oValue = Color::parse($oParserState);
157157
} elseif ($oParserState->comes("'") || $oParserState->comes('"')) {
158158
$oValue = CSSString::parse($oParserState);
159-
} elseif ($oParserState->comes("progid:") && $oParserState->getSettings()->bLenientParsing) {
159+
} elseif ($oParserState->comes('progid:') && $oParserState->getSettings()->bLenientParsing) {
160160
$oValue = self::parseMicrosoftFilter($oParserState);
161-
} elseif ($oParserState->comes("[")) {
161+
} elseif ($oParserState->comes('[')) {
162162
$oValue = LineName::parse($oParserState);
163-
} elseif ($oParserState->comes("U+")) {
163+
} elseif ($oParserState->comes('U+')) {
164164
$oValue = self::parseUnicodeRangeValue($oParserState);
165165
} else {
166166
$sNextChar = $oParserState->peek(1);
@@ -196,14 +196,14 @@ private static function parseMicrosoftFilter(ParserState $oParserState): CSSFunc
196196
private static function parseUnicodeRangeValue(ParserState $oParserState): string
197197
{
198198
$iCodepointMaxLength = 6; // Code points outside BMP can use up to six digits
199-
$sRange = "";
200-
$oParserState->consume("U+");
199+
$sRange = '';
200+
$oParserState->consume('U+');
201201
do {
202202
if ($oParserState->comes('-')) {
203203
$iCodepointMaxLength = 13; // Max length is 2 six digit code points + the dash(-) between them
204204
}
205205
$sRange .= $oParserState->consume(1);
206-
} while (\strlen($sRange) < $iCodepointMaxLength && \preg_match("/[A-Fa-f0-9\\?-]/", $oParserState->peek()));
206+
} while (\strlen($sRange) < $iCodepointMaxLength && \preg_match('/[A-Fa-f0-9\\?-]/', $oParserState->peek()));
207207
return "U+{$sRange}";
208208
}
209209

tests/OutputFormatTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function spaceAfterListArgumentSeparator(): void
9090
'.main, .test {font: italic normal bold 16px/ 1.2 '
9191
. '"Helvetica", Verdana, sans-serif;background: white;}'
9292
. "\n@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}",
93-
$this->oDocument->render(OutputFormat::create()->setSpaceAfterListArgumentSeparator(" "))
93+
$this->oDocument->render(OutputFormat::create()->setSpaceAfterListArgumentSeparator(' '))
9494
);
9595
}
9696

tests/ParserTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function colorParsing(): void
122122
'r' => new Size(10.0, null, true, $oColor->getLineNo()),
123123
'g' => new Size(100.0, null, true, $oColor->getLineNo()),
124124
'b' => new Size(231.0, null, true, $oColor->getLineNo()),
125-
'a' => new Size("0000.3", null, true, $oColor->getLineNo()),
125+
'a' => new Size('0000.3', null, true, $oColor->getLineNo()),
126126
], $oColor->getColor());
127127
$aColorRule = $oRuleSet->getRules('outline-color');
128128
$oColor = $aColorRule[0]->getValue();
@@ -225,7 +225,7 @@ public function unicodeParsing(): void
225225
public function unicodeRangeParsing(): void
226226
{
227227
$oDoc = self::parsedStructureForFile('unicode-range');
228-
$sExpected = "@font-face {unicode-range: U+0100-024F,U+0259,U+1E??-2EFF,U+202F;}";
228+
$sExpected = '@font-face {unicode-range: U+0100-024F,U+0259,U+1E??-2EFF,U+202F;}';
229229
self::assertSame($sExpected, $oDoc->render());
230230
}
231231

@@ -240,23 +240,23 @@ public function specificity(): void
240240
$aSelectors = $oDeclarationBlock->getSelectors();
241241
foreach ($aSelectors as $oSelector) {
242242
switch ($oSelector->getSelector()) {
243-
case "#test .help":
243+
case '#test .help':
244244
self::assertSame(110, $oSelector->getSpecificity());
245245
break;
246-
case "#file":
246+
case '#file':
247247
self::assertSame(100, $oSelector->getSpecificity());
248248
break;
249-
case ".help:hover":
249+
case '.help:hover':
250250
self::assertSame(20, $oSelector->getSpecificity());
251251
break;
252-
case "ol li::before":
252+
case 'ol li::before':
253253
self::assertSame(3, $oSelector->getSpecificity());
254254
break;
255-
case "li.green":
255+
case 'li.green':
256256
self::assertSame(11, $oSelector->getSpecificity());
257257
break;
258258
default:
259-
self::fail("specificity: untested selector " . $oSelector->getSelector());
259+
self::fail('specificity: untested selector ' . $oSelector->getSelector());
260260
}
261261
}
262262
self::assertEquals([new Selector('#test .help', true)], $oDoc->getSelectorsBySpecificity('> 100'));
@@ -734,7 +734,7 @@ public function gridLineNameInFile(): void
734734
{
735735
$oDoc = self::parsedStructureForFile('grid-linename', Settings::create()->withMultibyteSupport(true));
736736
$sExpected = "div {grid-template-columns: [linename] 100px;}\n"
737-
. "span {grid-template-columns: [linename1 linename2] 100px;}";
737+
. 'span {grid-template-columns: [linename1 linename2] 100px;}';
738738
self::assertSame($sExpected, $oDoc->render());
739739
}
740740

@@ -754,7 +754,7 @@ public function emptyGridLineNameLenientInFile(): void
754754
public function invalidGridLineNameInFile(): void
755755
{
756756
$oDoc = self::parsedStructureForFile('invalid-grid-linename', Settings::create()->withMultibyteSupport(true));
757-
$sExpected = "div {}";
757+
$sExpected = 'div {}';
758758
self::assertSame($sExpected, $oDoc->render());
759759
}
760760

@@ -1122,7 +1122,7 @@ public function commentExtracting(): void
11221122
$importComments = $aNodes[0]->getComments();
11231123
self::assertCount(2, $importComments);
11241124
self::assertSame("*\n * Comments\n ", $importComments[0]->getComment());
1125-
self::assertSame(" Hell ", $importComments[1]->getComment());
1125+
self::assertSame(' Hell ', $importComments[1]->getComment());
11261126

11271127
// Declaration block.
11281128
$fooBarBlock = $aNodes[1];
@@ -1137,7 +1137,7 @@ public function commentExtracting(): void
11371137
$fooBarRule = $fooBarRules[0];
11381138
$fooBarRuleComments = $fooBarRule->getComments();
11391139
self::assertCount(1, $fooBarRuleComments);
1140-
self::assertSame(" Number 6 ", $fooBarRuleComments[0]->getComment());
1140+
self::assertSame(' Number 6 ', $fooBarRuleComments[0]->getComment());
11411141

11421142
// Media property.
11431143
$mediaComments = $aNodes[2]->getComments();
@@ -1147,13 +1147,13 @@ public function commentExtracting(): void
11471147
$mediaRules = $aNodes[2]->getContents();
11481148
$fooBarComments = $mediaRules[0]->getComments();
11491149
self::assertCount(1, $fooBarComments);
1150-
self::assertSame("* Number 10 *", $fooBarComments[0]->getComment());
1150+
self::assertSame('* Number 10 *', $fooBarComments[0]->getComment());
11511151

11521152
// Media -> declaration -> rule.
11531153
$fooBarRules = $mediaRules[0]->getRules();
11541154
$fooBarChildComments = $fooBarRules[0]->getComments();
11551155
self::assertCount(1, $fooBarChildComments);
1156-
self::assertSame("* Number 10b *", $fooBarChildComments[0]->getComment());
1156+
self::assertSame('* Number 10b *', $fooBarChildComments[0]->getComment());
11571157
}
11581158

11591159
/**
@@ -1167,7 +1167,7 @@ public function flatCommentExtracting(): void
11671167
$divRules = $contents[0]->getRules();
11681168
$comments = $divRules[0]->getComments();
11691169
self::assertCount(1, $comments);
1170-
self::assertSame("Find Me!", $comments[0]->getComment());
1170+
self::assertSame('Find Me!', $comments[0]->getComment());
11711171
}
11721172

11731173
/**
@@ -1180,7 +1180,7 @@ public function topLevelCommentExtracting(): void
11801180
$contents = $doc->getContents();
11811181
$comments = $contents[0]->getComments();
11821182
self::assertCount(1, $comments);
1183-
self::assertSame("Find Me!", $comments[0]->getComment());
1183+
self::assertSame('Find Me!', $comments[0]->getComment());
11841184
}
11851185

11861186
/**
@@ -1235,7 +1235,7 @@ public function scientificNotationSizeValuesInFile(): void
12351235
public function lonelyImport(): void
12361236
{
12371237
$oDoc = self::parsedStructureForFile('lonely-import');
1238-
$sExpected = "@import url(\"example.css\") only screen and (max-width: 600px);";
1238+
$sExpected = '@import url("example.css") only screen and (max-width: 600px);';
12391239
self::assertSame($sExpected, $oDoc->render());
12401240
}
12411241

tests/RuleSet/LenientParsingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function endTokenPositive(): void
8181
$sFile = __DIR__ . '/../fixtures/-end-token.css';
8282
$oParser = new Parser(\file_get_contents($sFile), Settings::create()->withLenientParsing(true));
8383
$oResult = $oParser->parse();
84-
self::assertSame("", $oResult->render());
84+
self::assertSame('', $oResult->render());
8585
}
8686

8787
/**
@@ -103,7 +103,7 @@ public function endToken2Positive(): void
103103
*/
104104
public function localeTrap(): void
105105
{
106-
\setlocale(LC_ALL, "pt_PT", "no");
106+
\setlocale(LC_ALL, 'pt_PT', 'no');
107107
$sFile = __DIR__ . '/../fixtures/-fault-tolerance.css';
108108
$oParser = new Parser(\file_get_contents($sFile), Settings::create()->withLenientParsing(true));
109109
$oResult = $oParser->parse();

0 commit comments

Comments
 (0)