From be178dcb00efecf81faa82409dcd7bc12dfaf298 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 23 Feb 2025 23:22:56 +0100 Subject: [PATCH 1/2] [CLEANUP] Avoid Hungarian notation for `string*` Part of #756 --- src/OutputFormat.php | 6 ++-- src/Parsing/ParserState.php | 56 ++++++++++++++++---------------- src/RuleSet/DeclarationBlock.php | 12 +++---- src/Value/CSSString.php | 22 ++++++------- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/src/OutputFormat.php b/src/OutputFormat.php index 86b8b6406..caec89a5c 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -13,7 +13,7 @@ class OutputFormat * * @internal since 8.8.0, will be made private in 9.0.0 */ - public $sStringQuotingType = '"'; + public $stringQuotingType = '"'; /** * Output RGB colors in hash notation if possible @@ -305,7 +305,7 @@ public function __call(string $sMethodName, array $aArguments) */ public function getStringQuotingType(): string { - return $this->sStringQuotingType; + return $this->stringQuotingType; } /** @@ -313,7 +313,7 @@ public function getStringQuotingType(): string */ public function setStringQuotingType(string $quotingType): self { - $this->sStringQuotingType = $quotingType; + $this->stringQuotingType = $quotingType; return $this; } diff --git a/src/Parsing/ParserState.php b/src/Parsing/ParserState.php index 5a91d6623..35e495cbf 100644 --- a/src/Parsing/ParserState.php +++ b/src/Parsing/ParserState.php @@ -233,15 +233,15 @@ public function consumeWhiteSpace(): array } /** - * @param string $sString + * @param string $string * @param bool $caseInsensitive */ - public function comes($sString, $caseInsensitive = false): bool + public function comes($string, $caseInsensitive = false): bool { - $sPeek = $this->peek(\strlen($sString)); + $sPeek = $this->peek(\strlen($string)); return ($sPeek == '') ? false - : $this->streql($sPeek, $sString, $caseInsensitive); + : $this->streql($sPeek, $string, $caseInsensitive); } /** @@ -390,16 +390,16 @@ private function inputLeft(): string } /** - * @param string $sString1 - * @param string $sString2 + * @param string $string1 + * @param string $string2 * @param bool $caseInsensitive */ - public function streql($sString1, $sString2, $caseInsensitive = true): bool + public function streql($string1, $string2, $caseInsensitive = true): bool { if ($caseInsensitive) { - return $this->strtolower($sString1) === $this->strtolower($sString2); + return $this->strtolower($string1) === $this->strtolower($string2); } else { - return $sString1 === $sString2; + return $string1 === $string2; } } @@ -412,14 +412,14 @@ public function backtrack($iAmount): void } /** - * @param string $sString + * @param string $string */ - public function strlen($sString): int + public function strlen($string): int { if ($this->parserSettings->bMultibyteSupport) { - return \mb_strlen($sString, $this->charset); + return \mb_strlen($string, $this->charset); } else { - return \strlen($sString); + return \strlen($string); } } @@ -445,63 +445,63 @@ private function substr($iStart, $length): string } /** - * @param string $sString + * @param string $string */ - private function strtolower($sString): string + private function strtolower($string): string { if ($this->parserSettings->bMultibyteSupport) { - return \mb_strtolower($sString, $this->charset); + return \mb_strtolower($string, $this->charset); } else { - return \strtolower($sString); + return \strtolower($string); } } /** - * @param string $sString + * @param string $string * * @return array * * @throws SourceException if the charset is UTF-8 and the string contains invalid byte sequences */ - private function strsplit($sString) + private function strsplit($string) { if ($this->parserSettings->bMultibyteSupport) { if ($this->streql($this->charset, 'utf-8')) { - $result = \preg_split('//u', $sString, -1, PREG_SPLIT_NO_EMPTY); + $result = \preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY); if (!\is_array($result)) { throw new SourceException('`preg_split` failed with error ' . \preg_last_error()); } return $result; } else { - $length = \mb_strlen($sString, $this->charset); + $length = \mb_strlen($string, $this->charset); $result = []; for ($i = 0; $i < $length; ++$i) { - $result[] = \mb_substr($sString, $i, 1, $this->charset); + $result[] = \mb_substr($string, $i, 1, $this->charset); } return $result; } } else { - if ($sString === '') { + if ($string === '') { return []; } else { - return \str_split($sString); + return \str_split($string); } } } /** - * @param string $sString + * @param string $string * @param string $sNeedle * @param int $offset * * @return int|false */ - private function strpos($sString, $sNeedle, $offset) + private function strpos($string, $sNeedle, $offset) { if ($this->parserSettings->bMultibyteSupport) { - return \mb_strpos($sString, $sNeedle, $offset, $this->charset); + return \mb_strpos($string, $sNeedle, $offset, $this->charset); } else { - return \strpos($sString, $sNeedle, $offset); + return \strpos($string, $sNeedle, $offset); } } } diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index a39eaaa80..95003feac 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -45,18 +45,18 @@ public static function parse(ParserState $parserState, $list = null) $result = new DeclarationBlock($parserState->currentLine()); try { $aSelectorParts = []; - $sStringWrapperChar = false; + $stringWrapperChar = false; do { $aSelectorParts[] = $parserState->consume(1) . $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $comments); if (\in_array($parserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') { - if ($sStringWrapperChar === false) { - $sStringWrapperChar = $parserState->peek(); - } elseif ($sStringWrapperChar == $parserState->peek()) { - $sStringWrapperChar = false; + if ($stringWrapperChar === false) { + $stringWrapperChar = $parserState->peek(); + } elseif ($stringWrapperChar == $parserState->peek()) { + $stringWrapperChar = false; } } - } while (!\in_array($parserState->peek(), ['{', '}'], true) || $sStringWrapperChar !== false); + } while (!\in_array($parserState->peek(), ['{', '}'], true) || $stringWrapperChar !== false); $result->setSelectors(\implode('', $aSelectorParts), $list); if ($parserState->comes('{')) { $parserState->consume(1); diff --git a/src/Value/CSSString.php b/src/Value/CSSString.php index 496b94683..7ccdedaa2 100644 --- a/src/Value/CSSString.php +++ b/src/Value/CSSString.php @@ -20,15 +20,15 @@ class CSSString extends PrimitiveValue /** * @var string */ - private $sString; + private $string; /** - * @param string $sString + * @param string $string * @param int<0, max> $lineNumber */ - public function __construct($sString, $lineNumber = 0) + public function __construct($string, $lineNumber = 0) { - $this->sString = $sString; + $this->string = $string; parent::__construct($lineNumber); } @@ -75,11 +75,11 @@ public static function parse(ParserState $parserState): CSSString } /** - * @param string $sString + * @param string $string */ - public function setString($sString): void + public function setString($string): void { - $this->sString = $sString; + $this->string = $string; } /** @@ -87,7 +87,7 @@ public function setString($sString): void */ public function getString() { - return $this->sString; + return $this->string; } public function __toString(): string @@ -97,8 +97,8 @@ public function __toString(): string public function render(OutputFormat $outputFormat): string { - $sString = \addslashes($this->sString); - $sString = \str_replace("\n", '\\A', $sString); - return $outputFormat->getStringQuotingType() . $sString . $outputFormat->getStringQuotingType(); + $string = \addslashes($this->string); + $string = \str_replace("\n", '\\A', $string); + return $outputFormat->getStringQuotingType() . $string . $outputFormat->getStringQuotingType(); } } From c90e96c8e28733911dc7595012c8e7f3db0a967e Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Mon, 24 Feb 2025 10:48:22 +0100 Subject: [PATCH 2/2] Changes suggested in code review --- src/RuleSet/DeclarationBlock.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 95003feac..5d0258986 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -45,18 +45,18 @@ public static function parse(ParserState $parserState, $list = null) $result = new DeclarationBlock($parserState->currentLine()); try { $aSelectorParts = []; - $stringWrapperChar = false; + $stringWrapperCharacter = false; do { $aSelectorParts[] = $parserState->consume(1) . $parserState->consumeUntil(['{', '}', '\'', '"'], false, false, $comments); if (\in_array($parserState->peek(), ['\'', '"'], true) && \substr(\end($aSelectorParts), -1) != '\\') { - if ($stringWrapperChar === false) { - $stringWrapperChar = $parserState->peek(); - } elseif ($stringWrapperChar == $parserState->peek()) { - $stringWrapperChar = false; + if ($stringWrapperCharacter === false) { + $stringWrapperCharacter = $parserState->peek(); + } elseif ($stringWrapperCharacter == $parserState->peek()) { + $stringWrapperCharacter = false; } } - } while (!\in_array($parserState->peek(), ['{', '}'], true) || $stringWrapperChar !== false); + } while (!\in_array($parserState->peek(), ['{', '}'], true) || $stringWrapperCharacter !== false); $result->setSelectors(\implode('', $aSelectorParts), $list); if ($parserState->comes('{')) { $parserState->consume(1);