Skip to content

[CLEANUP] Avoid Hungarian notation in DeclarationBlock #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => $selector) {
if ($selector->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
Loading