Skip to content

Commit e1f8bd3

Browse files
authored
[CLEANUP] Refactor ::getAllDeclarationBlocks() (#990)
Part of #994.
1 parent 0bfa3f3 commit e1f8bd3

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/CSSList/CSSBlockList.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ 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 */
3130
$result = [];
32-
$this->allDeclarationBlocks($result);
31+
32+
foreach ($this->contents as $item) {
33+
if ($item instanceof DeclarationBlock) {
34+
$result[] = $item;
35+
} elseif ($item instanceof CSSBlockList) {
36+
$result = \array_merge($result, $item->getAllDeclarationBlocks());
37+
}
38+
}
39+
3340
return $result;
3441
}
3542

0 commit comments

Comments
 (0)