Skip to content
Merged
Changes from 1 commit
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 = '===';
$specificitySearchResults = \explode(' ', $specificitySearch);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be named with something like 'parts', 'elements' or 'components'. The input string contains either a number (e.g. "1"), or an operator and a number (e.g. ">= 1"). The result goes into $result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe $expressionParts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I think that works. It's only used locally in that small section of code.

$targetSpecificity = $specificitySearchResults[0];
if (\count($specificitySearchResults) > 1) {
$comparator = $specificitySearchResults[0];
$targetSpecificity = $specificitySearchResults[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