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

MyIntervals / PHP-CSS-Parser / 12973829822

26 Jan 2025 10:32AM UTC coverage: 42.018% (-0.2%) from 42.261%
12973829822

Pull #809

github

web-flow
Merge 1b26da12f into 7c6845f83
Pull Request #809: [BUGFIX] Drop `@covers` annotation referencing inexistent method

866 of 2061 relevant lines covered (42.02%)

6.56 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
    protected function allDeclarationBlocks(array &$aResult): void
×
35
    {
36
        foreach ($this->aContents as $mContent) {
×
37
            if ($mContent instanceof DeclarationBlock) {
×
38
                $aResult[] = $mContent;
×
39
            } elseif ($mContent instanceof CSSBlockList) {
×
40
                $mContent->allDeclarationBlocks($aResult);
×
41
            }
42
        }
43
    }
×
44

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

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

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