Skip to content

Commit a28ad75

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

File tree

14 files changed

+51
-50
lines changed

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
}

0 commit comments

Comments
 (0)