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

MyIntervals / PHP-CSS-Parser / 13921221957

18 Mar 2025 10:41AM UTC coverage: 51.499% (-5.3%) from 56.839%
13921221957

push

github

web-flow
[TASK] Reduce and finetune the scope of `@covers` annotations (#1188)

The legacy tests are not very focused. Until we have split them
up, try to avoid false positives for code coverage.

Also add `@covers` annotations for the parent classes of the
tested classes.

945 of 1835 relevant lines covered (51.5%)

6.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.0
/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\RuleSet;
12
use Sabberworm\CSS\Value\Value;
13

14
/**
15
 * This class represents the root of a parsed CSS file. It contains all top-level CSS contents: mostly declaration
16
 * blocks, but also any at-rules encountered (`Import` and `Charset`).
17
 */
18
class Document extends CSSBlockList
19
{
20
    /**
21
     * @throws SourceException
22
     *
23
     * @internal since V8.8.0
24
     */
25
    public static function parse(ParserState $parserState): Document
×
26
    {
27
        $document = new Document($parserState->currentLine());
×
28
        CSSList::parseList($parserState, $document);
×
29

30
        return $document;
×
31
    }
32

33
    /**
34
     * Returns all `Value` objects found recursively in `Rule`s in the tree.
35
     *
36
     * @param CSSList|RuleSet|string $element
37
     *        the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
38
     *        If a string is given, it is used as rule name filter.
39
     * @param bool $searchInFunctionArguments whether to also return Value objects used as Function arguments.
40
     *
41
     * @return array<int, Value>
42
     *
43
     * @see RuleSet->getRules()
44
     */
45
    public function getAllValues($element = null, bool $searchInFunctionArguments = false): array
×
46
    {
47
        $searchString = null;
×
48
        if ($element === null) {
×
49
            $element = $this;
×
50
        } elseif (\is_string($element)) {
×
51
            $searchString = $element;
×
52
            $element = $this;
×
53
        }
54
        /** @var array<int, Value> $result */
55
        $result = [];
×
56
        $this->allValues($element, $result, $searchString, $searchInFunctionArguments);
×
57
        return $result;
×
58
    }
59

60
    /**
61
     * Returns all `Selector` objects with the requested specificity found recursively in the tree.
62
     *
63
     * Note that this does not yield the full `DeclarationBlock` that the selector belongs to
64
     * (and, currently, there is no way to get to that).
65
     *
66
     * @param string|null $specificitySearch
67
     *        An optional filter by specificity.
68
     *        May contain a comparison operator and a number or just a number (defaults to "==").
69
     *
70
     * @return array<int, Selector>
71
     * @example `getSelectorsBySpecificity('>= 100')`
72
     */
73
    public function getSelectorsBySpecificity(?string $specificitySearch = null): array
×
74
    {
75
        /** @var array<int, Selector> $result */
76
        $result = [];
×
77
        $this->allSelectors($result, $specificitySearch);
×
78
        return $result;
×
79
    }
80

81
    /**
82
     * Overrides `render()` to make format argument optional.
83
     */
84
    public function render(?OutputFormat $outputFormat = null): string
10✔
85
    {
86
        if ($outputFormat === null) {
10✔
87
            $outputFormat = new OutputFormat();
2✔
88
        }
89
        return $outputFormat->getFormatter()->comments($this) . $this->renderListContents($outputFormat);
10✔
90
    }
91

92
    public function isRootList(): bool
11✔
93
    {
94
        return true;
11✔
95
    }
96
}
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