Skip to content

Commit 5709945

Browse files
committed
[CLEANUP] Refactor ::getAllDeclarationBlocks()
Part of #994.
1 parent a1f9f58 commit 5709945

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/CSSList/CSSBlockList.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,23 @@ abstract class CSSBlockList extends CSSList
2323
/**
2424
* Gets all `DeclarationBlock` objects recursively, no matter how deeply nested the selectors are.
2525
*
26-
* @return array<int, DeclarationBlock>
26+
* @return list<DeclarationBlock>
2727
*/
2828
public function getAllDeclarationBlocks(): array
2929
{
30-
/** @var array<int, DeclarationBlock> $result */
30+
/** @var list<DeclarationBlock> $result */
3131
$result = [];
32-
$this->allDeclarationBlocks($result);
32+
33+
foreach ($this->contents as $directSibling) {
34+
if ($directSibling instanceof DeclarationBlock) {
35+
$result[] = $directSibling;
36+
} elseif ($directSibling instanceof CSSBlockList) {
37+
foreach ($directSibling->getAllDeclarationBlocks() as $grandchild) {
38+
$result[] = $grandchild;
39+
}
40+
}
41+
}
42+
3343
return $result;
3444
}
3545

0 commit comments

Comments
 (0)