Skip to content
Merged
Changes from 2 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
40 changes: 20 additions & 20 deletions src/CSSList/CSSBlockList.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,42 +96,42 @@ protected function allValues(
*/
protected function allSelectors(array &$result, $specificitySearch = null): void
{
/** @var array<int, DeclarationBlock> $aDeclarationBlocks */
$aDeclarationBlocks = [];
$this->allDeclarationBlocks($aDeclarationBlocks);
foreach ($aDeclarationBlocks as $oBlock) {
/** @var array<int, DeclarationBlock> $declarationBlocks */
$declarationBlocks = [];
$this->allDeclarationBlocks($declarationBlocks);
foreach ($declarationBlocks as $oBlock) {
foreach ($oBlock->getSelectors() as $selector) {
if ($specificitySearch === null) {
$result[] = $selector;
} else {
$sComparator = '===';
$aSpecificitySearch = \explode(' ', $specificitySearch);
$iTargetSpecificity = $aSpecificitySearch[0];
if (\count($aSpecificitySearch) > 1) {
$sComparator = $aSpecificitySearch[0];
$iTargetSpecificity = $aSpecificitySearch[1];
$comparator = '===';
$expressionParts = \explode(' ', $specificitySearch);
$targetSpecificity = $expressionParts[0];
if (\count($expressionParts) > 1) {
$comparator = $expressionParts[0];
$targetSpecificity = $expressionParts[1];
}
$iTargetSpecificity = (int) $iTargetSpecificity;
$iSelectorSpecificity = $selector->getSpecificity();
$bMatches = false;
switch ($sComparator) {
$targetSpecificity = (int) $targetSpecificity;
$selectorSpecificity = $selector->getSpecificity();
$hasMatches = false;
Copy link
Collaborator

@JakeQZ JakeQZ Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I missed this in the previous review.

I don't think "has" is correct here. The equivalent linguistic phrase is "it matches" rather than "it has matches" - i.e. "matches" is a verb rather than a noun.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better late than never. ;-) I've come up with a different name and repushed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe comparatorMatched?

switch ($comparator) {
case '<=':
$bMatches = $iSelectorSpecificity <= $iTargetSpecificity;
$hasMatches = $selectorSpecificity <= $targetSpecificity;
break;
case '<':
$bMatches = $iSelectorSpecificity < $iTargetSpecificity;
$hasMatches = $selectorSpecificity < $targetSpecificity;
break;
case '>=':
$bMatches = $iSelectorSpecificity >= $iTargetSpecificity;
$hasMatches = $selectorSpecificity >= $targetSpecificity;
break;
case '>':
$bMatches = $iSelectorSpecificity > $iTargetSpecificity;
$hasMatches = $selectorSpecificity > $targetSpecificity;
break;
default:
$bMatches = $iSelectorSpecificity === $iTargetSpecificity;
$hasMatches = $selectorSpecificity === $targetSpecificity;
break;
}
if ($bMatches) {
if ($hasMatches) {
$result[] = $selector;
}
}
Expand Down