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

MyIntervals / PHP-CSS-Parser / 13344937658

15 Feb 2025 12:18PM UTC coverage: 50.453% (-0.05%) from 50.498%
13344937658

Pull #932

github

web-flow
Merge b7989b0ad into e1fa3b678
Pull Request #932: [TASK] Drop redundant constructor code

947 of 1877 relevant lines covered (50.45%)

11.35 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 array<int, DeclarationBlock> $result
25
     */
26
    protected function allDeclarationBlocks(array &$result): void
×
27
    {
28
        foreach ($this->contents as $item) {
×
29
            if ($item instanceof DeclarationBlock) {
×
30
                $result[] = $item;
×
31
            } elseif ($item instanceof CSSBlockList) {
×
32
                $item->allDeclarationBlocks($result);
×
33
            }
34
        }
35
    }
×
36

37
    /**
38
     * @param array<int, RuleSet> $result
39
     */
40
    protected function allRuleSets(array &$result): void
×
41
    {
42
        foreach ($this->contents as $item) {
×
43
            if ($item instanceof RuleSet) {
×
44
                $result[] = $item;
×
45
            } elseif ($item instanceof CSSBlockList) {
×
46
                $item->allRuleSets($result);
×
47
            }
48
        }
49
    }
×
50

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

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