Skip to content

Commit

Permalink
[CLEANUP] Avoid Hungarian notation in DeclarationBlock
Browse files Browse the repository at this point in the history
Also fix some variable name collisions.

Part of #756
  • Loading branch information
oliverklee committed Feb 26, 2025
1 parent b3abf1a commit dc0bd3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
6 changes: 0 additions & 6 deletions config/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,6 @@ parameters:
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
identifier: foreach.valueOverwrite
count: 1
path: ../src/RuleSet/DeclarationBlock.php

-
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
identifier: notEqual.notAllowed
Expand Down
48 changes: 24 additions & 24 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DeclarationBlock extends RuleSet
/**
* @var array<int, Selector|string>
*/
private $aSelectors = [];
private $selectors = [];

/**
* @param CSSList|null $list
Expand Down Expand Up @@ -76,38 +76,38 @@ public static function parse(ParserState $parserState, $list = null)
}

/**
* @param array<int, Selector|string>|string $mSelector
* @param array<int, Selector|string>|string $selectors
* @param CSSList|null $list
*
* @throws UnexpectedTokenException
*/
public function setSelectors($mSelector, $list = null): void
public function setSelectors($selectors, $list = null): void
{
if (\is_array($mSelector)) {
$this->aSelectors = $mSelector;
if (\is_array($selectors)) {
$this->selectors = $selectors;
} else {
$this->aSelectors = \explode(',', $mSelector);
$this->selectors = \explode(',', $selectors);
}
foreach ($this->aSelectors as $key => $mSelector) {
if (!($mSelector instanceof Selector)) {
foreach ($this->selectors as $key => $selector) {
if (!($selector instanceof Selector)) {
if ($list === null || !($list instanceof KeyFrame)) {
if (!Selector::isValid($mSelector)) {
if (!Selector::isValid($selector)) {
throw new UnexpectedTokenException(
"Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.",
$mSelector,
$selectors,
'custom'
);
}
$this->aSelectors[$key] = new Selector($mSelector);
$this->selectors[$key] = new Selector($selector);
} else {
if (!KeyframeSelector::isValid($mSelector)) {
if (!KeyframeSelector::isValid($selector)) {
throw new UnexpectedTokenException(
"Selector did not match '" . KeyframeSelector::SELECTOR_VALIDATION_RX . "'.",
$mSelector,
$selector,
'custom'
);
}
$this->aSelectors[$key] = new KeyframeSelector($mSelector);
$this->selectors[$key] = new KeyframeSelector($selector);
}
}
}
Expand All @@ -116,16 +116,16 @@ public function setSelectors($mSelector, $list = null): void
/**
* Remove one of the selectors of the block.
*
* @param Selector|string $mSelector
* @param Selector|string $selectorToRemove
*/
public function removeSelector($mSelector): bool
public function removeSelector($selectorToRemove): bool
{
if ($mSelector instanceof Selector) {
$mSelector = $mSelector->getSelector();
if ($selectorToRemove instanceof Selector) {
$selectorToRemove = $selectorToRemove->getSelector();
}
foreach ($this->aSelectors as $key => $selector) {
if ($selector->getSelector() === $mSelector) {
unset($this->aSelectors[$key]);
foreach ($this->selectors as $key => $subSelector) {
if ($subSelector->getSelector() === $selectorToRemove) {
unset($this->selectors[$key]);
return true;
}
}
Expand All @@ -137,7 +137,7 @@ public function removeSelector($mSelector): bool
*/
public function getSelectors()
{
return $this->aSelectors;
return $this->selectors;
}

/**
Expand All @@ -154,14 +154,14 @@ public function __toString(): string
public function render(OutputFormat $outputFormat): string
{
$result = $outputFormat->comments($this);
if (\count($this->aSelectors) === 0) {
if (\count($this->selectors) === 0) {
// If all the selectors have been removed, this declaration block becomes invalid
throw new OutputException('Attempt to print declaration block with missing selector', $this->lineNumber);
}
$result .= $outputFormat->sBeforeDeclarationBlock;
$result .= $outputFormat->implode(
$outputFormat->spaceBeforeSelectorSeparator() . ',' . $outputFormat->spaceAfterSelectorSeparator(),
$this->aSelectors
$this->selectors
);
$result .= $outputFormat->sAfterDeclarationBlockSelectors;
$result .= $outputFormat->spaceBeforeOpeningBrace() . '{';
Expand Down

0 comments on commit dc0bd3b

Please sign in to comment.