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

MyIntervals / PHP-CSS-Parser / 13057995224

30 Jan 2025 05:38PM UTC coverage: 45.006%. Remained the same
13057995224

push

github

web-flow
[CLEANUP] Avoid Hungarian notation in `CSSBlockList` (part 2) (#851)

Part of #756

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

793 of 1762 relevant lines covered (45.01%)

10.75 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
    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->aContents as $mContent) {
×
37
            if ($mContent instanceof DeclarationBlock) {
×
38
                $result[] = $mContent;
×
39
            } elseif ($mContent instanceof CSSBlockList) {
×
40
                $mContent->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->aContents as $mContent) {
×
51
            if ($mContent instanceof RuleSet) {
×
52
                $result[] = $mContent;
×
53
            } elseif ($mContent instanceof CSSBlockList) {
×
54
                $mContent->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)) {
×
83
                foreach ($element->getListComponents() as $mComponent) {
×
84
                    $this->allValues($mComponent, $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 */
NEW
100
        $declarationBlocks = [];
×
NEW
101
        $this->allDeclarationBlocks($declarationBlocks);
×
NEW
102
        foreach ($declarationBlocks as $oBlock) {
×
103
            foreach ($oBlock->getSelectors() as $selector) {
×
104
                if ($specificitySearch === null) {
×
105
                    $result[] = $selector;
×
106
                } else {
NEW
107
                    $comparator = '===';
×
NEW
108
                    $expressionParts = \explode(' ', $specificitySearch);
×
NEW
109
                    $targetSpecificity = $expressionParts[0];
×
NEW
110
                    if (\count($expressionParts) > 1) {
×
NEW
111
                        $comparator = $expressionParts[0];
×
NEW
112
                        $targetSpecificity = $expressionParts[1];
×
113
                    }
NEW
114
                    $targetSpecificity = (int) $targetSpecificity;
×
NEW
115
                    $selectorSpecificity = $selector->getSpecificity();
×
NEW
116
                    $comparatorMatched = false;
×
NEW
117
                    switch ($comparator) {
×
118
                        case '<=':
×
NEW
119
                            $comparatorMatched = $selectorSpecificity <= $targetSpecificity;
×
120
                            break;
×
121
                        case '<':
×
NEW
122
                            $comparatorMatched = $selectorSpecificity < $targetSpecificity;
×
123
                            break;
×
124
                        case '>=':
×
NEW
125
                            $comparatorMatched = $selectorSpecificity >= $targetSpecificity;
×
126
                            break;
×
127
                        case '>':
×
NEW
128
                            $comparatorMatched = $selectorSpecificity > $targetSpecificity;
×
129
                            break;
×
130
                        default:
NEW
131
                            $comparatorMatched = $selectorSpecificity === $targetSpecificity;
×
132
                            break;
×
133
                    }
NEW
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