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

MyIntervals / PHP-CSS-Parser / 12296501115

12 Dec 2024 12:34PM UTC coverage: 38.583%. Remained the same
12296501115

Pull #779

github

web-flow
Merge e1d954490 into 72899b583
Pull Request #779: [Dependabot] Update phpunit/phpunit requirement from 8.5.40 to 8.5.41

779 of 2019 relevant lines covered (38.58%)

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

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

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

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

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