• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MyIntervals / PHP-CSS-Parser / 14367827913

09 Apr 2025 10:04PM UTC coverage: 54.658% (+0.3%) from 54.382%
14367827913

push

github

web-flow
[CLEANUP] Remove `CSSBlockList::allDeclarationBlocks()` (#1239)

Change the one remaining usage instance to use `getAllDeclarationBlocks()`,
which was refactored in #990.

Part of #994.

0 of 1 new or added line in 1 file covered. (0.0%)

968 of 1771 relevant lines covered (54.66%)

7.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.0
/src/CSSList/CSSBlockList.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Sabberworm\CSS\CSSList;
6

7
use Sabberworm\CSS\CSSElement;
8
use Sabberworm\CSS\Property\Selector;
9
use Sabberworm\CSS\Rule\Rule;
10
use Sabberworm\CSS\RuleSet\DeclarationBlock;
11
use Sabberworm\CSS\RuleSet\RuleSet;
12
use Sabberworm\CSS\Value\CSSFunction;
13
use Sabberworm\CSS\Value\Value;
14
use Sabberworm\CSS\Value\ValueList;
15

16
/**
17
 * A `CSSBlockList` is a `CSSList` whose `DeclarationBlock`s are guaranteed to contain valid declaration blocks or
18
 * at-rules.
19
 *
20
 * Most `CSSList`s conform to this category but some at-rules (such as `@keyframes`) do not.
21
 */
22
abstract class CSSBlockList extends CSSList
23
{
24
    /**
25
     * Gets all `DeclarationBlock` objects recursively, no matter how deeply nested the selectors are.
26
     *
27
     * @return list<DeclarationBlock>
28
     */
29
    public function getAllDeclarationBlocks(): array
6✔
30
    {
31
        $result = [];
6✔
32

33
        foreach ($this->contents as $item) {
6✔
34
            if ($item instanceof DeclarationBlock) {
5✔
35
                $result[] = $item;
3✔
36
            } elseif ($item instanceof CSSBlockList) {
3✔
37
                $result = \array_merge($result, $item->getAllDeclarationBlocks());
1✔
38
            }
39
        }
40

41
        return $result;
6✔
42
    }
43

44
    /**
45
     * Returns all `RuleSet` objects recursively found in the tree, no matter how deeply nested the rule sets are.
46
     *
47
     * @return list<RuleSet>
48
     */
49
    public function getAllRuleSets(): array
9✔
50
    {
51
        $result = [];
9✔
52

53
        foreach ($this->contents as $item) {
9✔
54
            if ($item instanceof RuleSet) {
8✔
55
                $result[] = $item;
6✔
56
            } elseif ($item instanceof CSSBlockList) {
4✔
57
                $result = \array_merge($result, $item->getAllRuleSets());
2✔
58
            }
59
        }
60

61
        return $result;
9✔
62
    }
63

64
    /**
65
     * @param CSSElement|string $element
66
     * @param list<Value> $result
67
     */
68
    protected function allValues(
×
69
        $element,
70
        array &$result,
71
        ?string $searchString = null,
72
        bool $searchInFunctionArguments = false
73
    ): void {
74
        if ($element instanceof CSSBlockList) {
×
75
            foreach ($element->getContents() as $content) {
×
76
                $this->allValues($content, $result, $searchString, $searchInFunctionArguments);
×
77
            }
78
        } elseif ($element instanceof RuleSet) {
×
79
            foreach ($element->getRules($searchString) as $rule) {
×
80
                $this->allValues($rule, $result, $searchString, $searchInFunctionArguments);
×
81
            }
82
        } elseif ($element instanceof Rule) {
×
83
            $this->allValues($element->getValue(), $result, $searchString, $searchInFunctionArguments);
×
84
        } elseif ($element instanceof ValueList) {
×
85
            if ($searchInFunctionArguments || !($element instanceof CSSFunction)) {
×
86
                foreach ($element->getListComponents() as $component) {
×
87
                    $this->allValues($component, $result, $searchString, $searchInFunctionArguments);
×
88
                }
89
            }
90
        } elseif ($element instanceof Value) {
×
91
            $result[] = $element;
×
92
        }
93
    }
×
94

95
    /**
96
     * @param list<Selector> $result
97
     */
98
    protected function allSelectors(array &$result, ?string $specificitySearch = null): void
×
99
    {
NEW
100
        foreach ($this->getAllDeclarationBlocks() as $declarationBlock) {
×
101
            foreach ($declarationBlock->getSelectors() as $selector) {
×
102
                if ($specificitySearch === null) {
×
103
                    $result[] = $selector;
×
104
                } else {
105
                    $comparator = '===';
×
106
                    $expressionParts = \explode(' ', $specificitySearch);
×
107
                    $targetSpecificity = $expressionParts[0];
×
108
                    if (\count($expressionParts) > 1) {
×
109
                        $comparator = $expressionParts[0];
×
110
                        $targetSpecificity = $expressionParts[1];
×
111
                    }
112
                    $targetSpecificity = (int) $targetSpecificity;
×
113
                    $selectorSpecificity = $selector->getSpecificity();
×
114
                    $comparatorMatched = false;
×
115
                    switch ($comparator) {
×
116
                        case '<=':
×
117
                            $comparatorMatched = $selectorSpecificity <= $targetSpecificity;
×
118
                            break;
×
119
                        case '<':
×
120
                            $comparatorMatched = $selectorSpecificity < $targetSpecificity;
×
121
                            break;
×
122
                        case '>=':
×
123
                            $comparatorMatched = $selectorSpecificity >= $targetSpecificity;
×
124
                            break;
×
125
                        case '>':
×
126
                            $comparatorMatched = $selectorSpecificity > $targetSpecificity;
×
127
                            break;
×
128
                        default:
129
                            $comparatorMatched = $selectorSpecificity === $targetSpecificity;
×
130
                            break;
×
131
                    }
132
                    if ($comparatorMatched) {
×
133
                        $result[] = $selector;
×
134
                    }
135
                }
136
            }
137
        }
138
    }
×
139
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc