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

MyIntervals / PHP-CSS-Parser / 13226444511

09 Feb 2025 02:05PM UTC coverage: 49.156%. Remained the same
13226444511

Pull #888

github

web-flow
Merge b7f855337 into f7914f8b4
Pull Request #888: [TASK] Make constructors of CSS element classes `@internal`

932 of 1896 relevant lines covered (49.16%)

10.91 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace Sabberworm\CSS\CSSList;
6

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

15
/**
16
 * A `CSSBlockList` is a `CSSList` whose `DeclarationBlock`s are guaranteed to contain valid declaration blocks or
17
 * at-rules.
18
 *
19
 * Most `CSSList`s conform to this category but some at-rules (such as `@keyframes`) do not.
20
 */
21
abstract class CSSBlockList extends CSSList
22
{
23
    /**
24
     * @param int $lineNumber
25
     *
26
     * @internal since 8.8.0
27
     */
28
    public function __construct($lineNumber = 0)
×
29
    {
30
        parent::__construct($lineNumber);
×
31
    }
×
32

33
    /**
34
     * @param array<int, DeclarationBlock> $result
35
     */
36
    protected function allDeclarationBlocks(array &$result): void
×
37
    {
38
        foreach ($this->contents as $item) {
×
39
            if ($item instanceof DeclarationBlock) {
×
40
                $result[] = $item;
×
41
            } elseif ($item instanceof CSSBlockList) {
×
42
                $item->allDeclarationBlocks($result);
×
43
            }
44
        }
45
    }
×
46

47
    /**
48
     * @param array<int, RuleSet> $result
49
     */
50
    protected function allRuleSets(array &$result): void
×
51
    {
52
        foreach ($this->contents as $item) {
×
53
            if ($item instanceof RuleSet) {
×
54
                $result[] = $item;
×
55
            } elseif ($item instanceof CSSBlockList) {
×
56
                $item->allRuleSets($result);
×
57
            }
58
        }
59
    }
×
60

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

95
    /**
96
     * @param array<int, Selector> $result
97
     * @param string|null $specificitySearch
98
     */
99
    protected function allSelectors(array &$result, $specificitySearch = null): void
×
100
    {
101
        /** @var array<int, DeclarationBlock> $declarationBlocks */
102
        $declarationBlocks = [];
×
103
        $this->allDeclarationBlocks($declarationBlocks);
×
104
        foreach ($declarationBlocks as $oBlock) {
×
105
            foreach ($oBlock->getSelectors() as $selector) {
×
106
                if ($specificitySearch === null) {
×
107
                    $result[] = $selector;
×
108
                } else {
109
                    $comparator = '===';
×
110
                    $expressionParts = \explode(' ', $specificitySearch);
×
111
                    $targetSpecificity = $expressionParts[0];
×
112
                    if (\count($expressionParts) > 1) {
×
113
                        $comparator = $expressionParts[0];
×
114
                        $targetSpecificity = $expressionParts[1];
×
115
                    }
116
                    $targetSpecificity = (int) $targetSpecificity;
×
117
                    $selectorSpecificity = $selector->getSpecificity();
×
118
                    $comparatorMatched = false;
×
119
                    switch ($comparator) {
×
120
                        case '<=':
×
121
                            $comparatorMatched = $selectorSpecificity <= $targetSpecificity;
×
122
                            break;
×
123
                        case '<':
×
124
                            $comparatorMatched = $selectorSpecificity < $targetSpecificity;
×
125
                            break;
×
126
                        case '>=':
×
127
                            $comparatorMatched = $selectorSpecificity >= $targetSpecificity;
×
128
                            break;
×
129
                        case '>':
×
130
                            $comparatorMatched = $selectorSpecificity > $targetSpecificity;
×
131
                            break;
×
132
                        default:
133
                            $comparatorMatched = $selectorSpecificity === $targetSpecificity;
×
134
                            break;
×
135
                    }
136
                    if ($comparatorMatched) {
×
137
                        $result[] = $selector;
×
138
                    }
139
                }
140
            }
141
        }
142
    }
×
143
}
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

© 2026 Coveralls, Inc