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

MyIntervals / PHP-CSS-Parser / 12294614489

12 Dec 2024 10:35AM UTC coverage: 38.583%. Remained the same
12294614489

Pull #777

github

web-flow
Merge 01c6f866e into 428a2ebc8
Pull Request #777: [TASK] Upgrade to PHPStan 2.x and Rector 2.x

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

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

16.28
/src/CSSList/Document.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Sabberworm\CSS\CSSList;
6

7
use Sabberworm\CSS\OutputFormat;
8
use Sabberworm\CSS\Parsing\ParserState;
9
use Sabberworm\CSS\Parsing\SourceException;
10
use Sabberworm\CSS\Property\Selector;
11
use Sabberworm\CSS\RuleSet\DeclarationBlock;
12
use Sabberworm\CSS\RuleSet\RuleSet;
13
use Sabberworm\CSS\Value\Value;
14

15
/**
16
 * This class represents the root of a parsed CSS file. It contains all top-level CSS contents: mostly declaration
17
 * blocks, but also any at-rules encountered (`Import` and `Charset`).
18
 */
19
class Document extends CSSBlockList
20
{
21
    /**
22
     * @param int $iLineNo
23
     */
24
    public function __construct($iLineNo = 0)
9✔
25
    {
26
        parent::__construct($iLineNo);
9✔
27
    }
9✔
28

29
    /**
30
     * @throws SourceException
31
     */
32
    public static function parse(ParserState $oParserState): Document
68✔
33
    {
34
        $oDocument = new Document($oParserState->currentLine());
68✔
35
        CSSList::parseList($oParserState, $oDocument);
68✔
36
        return $oDocument;
55✔
37
    }
38

39
    /**
40
     * Gets all `DeclarationBlock` objects recursively, no matter how deeply nested the selectors are.
41
     * Aliased as `getAllSelectors()`.
42
     *
43
     * @return array<int, DeclarationBlock>
44
     */
NEW
45
    public function getAllDeclarationBlocks(): array
×
46
    {
47
        /** @var array<int, DeclarationBlock> $aResult */
48
        $aResult = [];
×
49
        $this->allDeclarationBlocks($aResult);
×
50
        return $aResult;
×
51
    }
52

53
    /**
54
     * Returns all `RuleSet` objects recursively found in the tree, no matter how deeply nested the rule sets are.
55
     *
56
     * @return array<int, RuleSet>
57
     */
NEW
58
    public function getAllRuleSets(): array
×
59
    {
60
        /** @var array<int, RuleSet> $aResult */
61
        $aResult = [];
×
62
        $this->allRuleSets($aResult);
×
63
        return $aResult;
×
64
    }
65

66
    /**
67
     * Returns all `Value` objects found recursively in `Rule`s in the tree.
68
     *
69
     * @param CSSList|RuleSet|string $mElement
70
     *        the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
71
     *        If a string is given, it is used as rule name filter.
72
     * @param bool $bSearchInFunctionArguments whether to also return Value objects used as Function arguments.
73
     *
74
     * @return array<int, Value>
75
     *
76
     * @see RuleSet->getRules()
77
     */
NEW
78
    public function getAllValues($mElement = null, $bSearchInFunctionArguments = false): array
×
79
    {
80
        $sSearchString = null;
×
81
        if ($mElement === null) {
×
82
            $mElement = $this;
×
83
        } elseif (\is_string($mElement)) {
×
84
            $sSearchString = $mElement;
×
85
            $mElement = $this;
×
86
        }
87
        /** @var array<int, Value> $aResult */
88
        $aResult = [];
×
89
        $this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments);
×
90
        return $aResult;
×
91
    }
92

93
    /**
94
     * Returns all `Selector` objects with the requested specificity found recursively in the tree.
95
     *
96
     * Note that this does not yield the full `DeclarationBlock` that the selector belongs to
97
     * (and, currently, there is no way to get to that).
98
     *
99
     * @param string|null $sSpecificitySearch
100
     *        An optional filter by specificity.
101
     *        May contain a comparison operator and a number or just a number (defaults to "==").
102
     *
103
     * @return array<int, Selector>
104
     * @example `getSelectorsBySpecificity('>= 100')`
105
     */
NEW
106
    public function getSelectorsBySpecificity($sSpecificitySearch = null): array
×
107
    {
108
        /** @var array<int, Selector> $aResult */
109
        $aResult = [];
×
110
        $this->allSelectors($aResult, $sSpecificitySearch);
×
111
        return $aResult;
×
112
    }
113

114
    /**
115
     * Expands all shorthand properties to their long value.
116
     *
117
     * @deprecated since 8.7.0, will be removed without substitution in version 9.0 in #511
118
     */
119
    public function expandShorthands(): void
×
120
    {
121
        foreach ($this->getAllDeclarationBlocks() as $oDeclaration) {
×
122
            $oDeclaration->expandShorthands();
×
123
        }
124
    }
×
125

126
    /**
127
     * Create shorthands properties whenever possible.
128
     *
129
     * @deprecated since 8.7.0, will be removed without substitution in version 9.0 in #511
130
     */
131
    public function createShorthands(): void
×
132
    {
133
        foreach ($this->getAllDeclarationBlocks() as $oDeclaration) {
×
134
            $oDeclaration->createShorthands();
×
135
        }
136
    }
×
137

138
    /**
139
     * Overrides `render()` to make format argument optional.
140
     *
141
     * @param OutputFormat|null $oOutputFormat
142
     */
143
    public function render(?OutputFormat $oOutputFormat = null): string
×
144
    {
145
        if ($oOutputFormat === null) {
×
146
            $oOutputFormat = new OutputFormat();
×
147
        }
148
        return $oOutputFormat->comments($this) . $this->renderListContents($oOutputFormat);
×
149
    }
150

151
    public function isRootList(): bool
×
152
    {
153
        return true;
×
154
    }
155
}
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