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

MyIntervals / PHP-CSS-Parser / 13304692697

13 Feb 2025 09:37AM UTC coverage: 49.156%. Remained the same
13304692697

Pull #917

github

web-flow
Merge c6e539a10 into 537f5e837
Pull Request #917: [CLEANUP] Avoid Hungarian notation for `component`

0 of 4 new or added lines in 2 files covered. (0.0%)

932 of 1896 relevant lines covered (49.16%)

11.42 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<0, max> $lineNumber
25
     */
26
    public function __construct($lineNumber = 0)
×
27
    {
28
        parent::__construct($lineNumber);
×
29
    }
×
30

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

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

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

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