Skip to content

Commit 3cc910e

Browse files
committed
[CLEANUP] Refactor Document::getAllDeclarationBlocks()
This is a pre-patch to moving `getAllDeclarationBlocks()` up to `CSSBlockList`.
1 parent 66fbb73 commit 3cc910e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/CSSList/Document.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@ public static function parse(ParserState $parserState): Document
3333
/**
3434
* Gets all `DeclarationBlock` objects recursively, no matter how deeply nested the selectors are.
3535
*
36-
* @return array<int, DeclarationBlock>
36+
* @return list<DeclarationBlock>
3737
*/
3838
public function getAllDeclarationBlocks(): array
3939
{
40-
/** @var array<int, DeclarationBlock> $result */
40+
/** @var list<DeclarationBlock> $result */
4141
$result = [];
42-
$this->allDeclarationBlocks($result);
42+
43+
foreach ($this->contents as $directSibling) {
44+
if ($directSibling instanceof DeclarationBlock) {
45+
$result[] = $directSibling;
46+
} elseif ($directSibling instanceof CSSBlockList) {
47+
$grandchildren = [];
48+
$directSibling->allDeclarationBlocks($grandchildren);
49+
foreach ($grandchildren as $grandchild) {
50+
$result[] = $grandchild;
51+
}
52+
}
53+
}
54+
4355
return $result;
4456
}
4557

0 commit comments

Comments
 (0)