Skip to content

Commit

Permalink
[CLEANUP] Avoid Hungarian notation in Settings (#1008)
Browse files Browse the repository at this point in the history
We'll change the direct accesses to use the accessors in
a later chance.

Part of #756
  • Loading branch information
oliverklee authored Feb 27, 2025
1 parent f661c96 commit 215c199
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function parseList(ParserState $parserState, CSSList $list): void
if (\is_string($parserState)) {
$parserState = new ParserState($parserState, Settings::create());
}
$usesLenientParsing = $parserState->getSettings()->bLenientParsing;
$usesLenientParsing = $parserState->getSettings()->lenientParsing;
$comments = [];
while (!$parserState->isEnd()) {
$comments = \array_merge($comments, $parserState->consumeWhiteSpace());
Expand Down Expand Up @@ -138,7 +138,7 @@ private static function parseListItem(ParserState $parserState, CSSList $list)
return $atRule;
} elseif ($parserState->comes('}')) {
if ($isRoot) {
if ($parserState->getSettings()->bLenientParsing) {
if ($parserState->getSettings()->lenientParsing) {
return DeclarationBlock::parse($parserState);
} else {
throw new SourceException('Unopened {', $parserState->currentLine());
Expand Down Expand Up @@ -215,7 +215,7 @@ private static function parseAtRule(ParserState $parserState)
// Unknown other at rule (font-face or such)
$arguments = \trim($parserState->consumeUntil('{', false, true));
if (\substr_count($arguments, '(') != \substr_count($arguments, ')')) {
if ($parserState->getSettings()->bLenientParsing) {
if ($parserState->getSettings()->lenientParsing) {
return null;
} else {
throw new SourceException('Unmatched brace count in media query', $parserState->currentLine());
Expand Down
14 changes: 7 additions & 7 deletions src/Parsing/ParserState.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($text, Settings $parserSettings, $lineNumber = 1)
$this->parserSettings = $parserSettings;
$this->text = $text;
$this->lineNumber = $lineNumber;
$this->setCharset($this->parserSettings->sDefaultCharset);
$this->setCharset($this->parserSettings->defaultCharset);
}

/**
Expand Down Expand Up @@ -151,7 +151,7 @@ public function parseCharacter($isForIdentifier)
{
if ($this->peek() === '\\') {
if (
$isForIdentifier && $this->parserSettings->bLenientParsing
$isForIdentifier && $this->parserSettings->lenientParsing
&& ($this->comes('\\0') || $this->comes('\\9'))
) {
// Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing.
Expand Down Expand Up @@ -215,7 +215,7 @@ public function consumeWhiteSpace(): array
while (\preg_match('/\\s/isSu', $this->peek()) === 1) {
$this->consume(1);
}
if ($this->parserSettings->bLenientParsing) {
if ($this->parserSettings->lenientParsing) {
try {
$comment = $this->consumeComment();
} catch (UnexpectedEOFException $e) {
Expand Down Expand Up @@ -416,7 +416,7 @@ public function backtrack($numberOfCharacters): void
*/
public function strlen($string): int
{
if ($this->parserSettings->bMultibyteSupport) {
if ($this->parserSettings->multibyteSupport) {
return \mb_strlen($string, $this->charset);
} else {
return \strlen($string);
Expand Down Expand Up @@ -449,7 +449,7 @@ private function substr($offset, $length): string
*/
private function strtolower($string): string
{
if ($this->parserSettings->bMultibyteSupport) {
if ($this->parserSettings->multibyteSupport) {
return \mb_strtolower($string, $this->charset);
} else {
return \strtolower($string);
Expand All @@ -465,7 +465,7 @@ private function strtolower($string): string
*/
private function strsplit($string)
{
if ($this->parserSettings->bMultibyteSupport) {
if ($this->parserSettings->multibyteSupport) {
if ($this->streql($this->charset, 'utf-8')) {
$result = \preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
if (!\is_array($result)) {
Expand Down Expand Up @@ -498,7 +498,7 @@ private function strsplit($string)
*/
private function strpos($haystack, $needle, $offset)
{
if ($this->parserSettings->bMultibyteSupport) {
if ($this->parserSettings->multibyteSupport) {
return \mb_strpos($haystack, $needle, $offset, $this->charset);
} else {
return \strpos($haystack, $needle, $offset);
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static function parse(ParserState $parserState): Rule
$parserState->consume(':');
$value = Value::parseValue($parserState, self::listDelimiterForRule($rule->getRule()));
$rule->setValue($value);
if ($parserState->getSettings()->bLenientParsing) {
if ($parserState->getSettings()->lenientParsing) {
while ($parserState->comes('\\')) {
$parserState->consume('\\');
$rule->addIeHack($parserState->consume());
Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function parse(ParserState $parserState, $list = null)
$parserState->consume(1);
}
} catch (UnexpectedTokenException $e) {
if ($parserState->getSettings()->bLenientParsing) {
if ($parserState->getSettings()->lenientParsing) {
if (!$parserState->comes('}')) {
$parserState->consumeUntil('}', false, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function parseRuleSet(ParserState $parserState, RuleSet $ruleSet):
}
while (!$parserState->comes('}')) {
$rule = null;
if ($parserState->getSettings()->bLenientParsing) {
if ($parserState->getSettings()->lenientParsing) {
try {
$rule = Rule::parse($parserState);
} catch (UnexpectedTokenException $e) {
Expand Down
18 changes: 9 additions & 9 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Settings
*
* @internal since 8.8.0, will be made private in 9.0.0
*/
public $bMultibyteSupport;
public $multibyteSupport;

/**
* The default charset for the CSS if no `@charset` declaration is found. Defaults to utf-8.
Expand All @@ -30,7 +30,7 @@ class Settings
*
* @internal since 8.8.0, will be made private in 9.0.0
*/
public $sDefaultCharset = 'utf-8';
public $defaultCharset = 'utf-8';

/**
* Whether the parser silently ignore invalid rules instead of choking on them.
Expand All @@ -39,11 +39,11 @@ class Settings
*
* @internal since 8.8.0, will be made private in 9.0.0
*/
public $bLenientParsing = true;
public $lenientParsing = true;

private function __construct()
{
$this->bMultibyteSupport = \extension_loaded('mbstring');
$this->multibyteSupport = \extension_loaded('mbstring');
}

public static function create(): self
Expand All @@ -59,9 +59,9 @@ public static function create(): self
*
* @return $this fluent interface
*/
public function withMultibyteSupport(bool $bMultibyteSupport = true): self
public function withMultibyteSupport(bool $multibyteSupport = true): self
{
$this->bMultibyteSupport = $bMultibyteSupport;
$this->multibyteSupport = $multibyteSupport;
return $this;
}

Expand All @@ -70,9 +70,9 @@ public function withMultibyteSupport(bool $bMultibyteSupport = true): self
*
* @return $this fluent interface
*/
public function withDefaultCharset(string $sDefaultCharset): self
public function withDefaultCharset(string $defaultCharset): self
{
$this->sDefaultCharset = $sDefaultCharset;
$this->defaultCharset = $defaultCharset;
return $this;
}

Expand All @@ -83,7 +83,7 @@ public function withDefaultCharset(string $sDefaultCharset): self
*/
public function withLenientParsing(bool $usesLenientParsing = true): self
{
$this->bLenientParsing = $usesLenientParsing;
$this->lenientParsing = $usesLenientParsing;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Value/LineName.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function parse(ParserState $parserState): LineName
$parserState->consumeWhiteSpace();
$aNames = [];
do {
if ($parserState->getSettings()->bLenientParsing) {
if ($parserState->getSettings()->lenientParsing) {
try {
$aNames[] = $parserState->parseIdentifier();
} catch (UnexpectedTokenException $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Value/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static function parsePrimitiveValue(ParserState $parserState)
$oValue = Color::parse($parserState);
} elseif ($parserState->comes("'") || $parserState->comes('"')) {
$oValue = CSSString::parse($parserState);
} elseif ($parserState->comes('progid:') && $parserState->getSettings()->bLenientParsing) {
} elseif ($parserState->comes('progid:') && $parserState->getSettings()->lenientParsing) {
$oValue = self::parseMicrosoftFilter($parserState);
} elseif ($parserState->comes('[')) {
$oValue = LineName::parse($parserState);
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function createReturnsANewInstanceForEachCall(): void
*/
public function multibyteSupportByDefaultStateOfMbStringExtension(): void
{
self::assertSame(\extension_loaded('mbstring'), $this->subject->bMultibyteSupport);
self::assertSame(\extension_loaded('mbstring'), $this->subject->multibyteSupport);
}

/**
Expand Down Expand Up @@ -78,15 +78,15 @@ public function withMultibyteSupportSetsMultibyteSupport(bool $value): void
{
$this->subject->withMultibyteSupport($value);

self::assertSame($value, $this->subject->bMultibyteSupport);
self::assertSame($value, $this->subject->multibyteSupport);
}

/**
* @test
*/
public function defaultCharsetByDefaultIsUtf8(): void
{
self::assertSame('utf-8', $this->subject->sDefaultCharset);
self::assertSame('utf-8', $this->subject->defaultCharset);
}

/**
Expand All @@ -105,15 +105,15 @@ public function withDefaultCharsetSetsDefaultCharset(): void
$charset = 'ISO-8859-1';
$this->subject->withDefaultCharset($charset);

self::assertSame($charset, $this->subject->sDefaultCharset);
self::assertSame($charset, $this->subject->defaultCharset);
}

/**
* @test
*/
public function lenientParsingByDefaultIsTrue(): void
{
self::assertTrue($this->subject->bLenientParsing);
self::assertTrue($this->subject->lenientParsing);
}

/**
Expand All @@ -132,7 +132,7 @@ public function withLenientParsingSetsLenientParsing(bool $value): void
{
$this->subject->withLenientParsing($value);

self::assertSame($value, $this->subject->bLenientParsing);
self::assertSame($value, $this->subject->lenientParsing);
}

/**
Expand All @@ -150,6 +150,6 @@ public function beStrictSetsLenientParsingToFalse(): void
{
$this->subject->beStrict();

self::assertFalse($this->subject->bLenientParsing);
self::assertFalse($this->subject->lenientParsing);
}
}

0 comments on commit 215c199

Please sign in to comment.