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

MyIntervals / PHP-CSS-Parser / 20772587941

07 Jan 2026 06:19AM UTC coverage: 70.316% (+1.1%) from 69.191%
20772587941

Pull #1442

github

web-flow
Merge 44fbf83d1 into 2b61cd568
Pull Request #1442: [FEATURE] Convert legacy color notation to modern css 4 notation

4 of 9 new or added lines in 2 files covered. (44.44%)

65 existing lines in 7 files now uncovered.

1400 of 1991 relevant lines covered (70.32%)

32.28 hits per line

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

36.36
/src/Value/URL.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Sabberworm\CSS\Value;
6

7
use Sabberworm\CSS\OutputFormat;
8
use Sabberworm\CSS\Parsing\ParserState;
9
use Sabberworm\CSS\Parsing\SourceException;
10
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
11
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
12
use Sabberworm\CSS\ShortClassNameProvider;
13

14
/**
15
 * This class represents URLs in CSS. `URL`s always output in `URL("")` notation.
16
 */
17
class URL extends PrimitiveValue
18
{
19
    use ShortClassNameProvider;
20

21
    /**
22
     * @var CSSString
23
     */
24
    private $url;
25

26
    /**
27
     * @param int<1, max>|null $lineNumber
28
     */
29
    public function __construct(CSSString $url, ?int $lineNumber = null)
8✔
30
    {
31
        parent::__construct($lineNumber);
8✔
32
        $this->url = $url;
8✔
33
    }
8✔
34

35
    /**
36
     * @throws SourceException
37
     * @throws UnexpectedEOFException
38
     * @throws UnexpectedTokenException
39
     *
40
     * @internal since V8.8.0
41
     */
42
    public static function parse(ParserState $parserState): URL
×
43
    {
44
        $anchor = $parserState->anchor();
×
45
        $identifier = '';
×
46
        for ($i = 0; $i < 3; $i++) {
×
UNCOV
47
            $character = $parserState->parseCharacter(true);
×
48
            if ($character === null) {
×
UNCOV
49
                break;
×
50
            }
51
            $identifier .= $character;
×
52
        }
53
        $useUrl = $parserState->streql($identifier, 'url');
×
UNCOV
54
        if ($useUrl) {
×
55
            $parserState->consumeWhiteSpace();
×
UNCOV
56
            $parserState->consume('(');
×
57
        } else {
58
            $anchor->backtrack();
×
59
        }
60
        $parserState->consumeWhiteSpace();
×
61
        $result = new URL(CSSString::parse($parserState), $parserState->currentLine());
×
UNCOV
62
        if ($useUrl) {
×
63
            $parserState->consumeWhiteSpace();
×
UNCOV
64
            $parserState->consume(')');
×
65
        }
UNCOV
66
        return $result;
×
67
    }
68

69
    public function setURL(CSSString $url): void
1✔
70
    {
71
        $this->url = $url;
1✔
72
    }
1✔
73

74
    public function getURL(): CSSString
2✔
75
    {
76
        return $this->url;
2✔
77
    }
78

79
    /**
80
     * @return non-empty-string
81
     */
UNCOV
82
    public function render(OutputFormat $outputFormat): string
×
83
    {
UNCOV
84
        return "url({$this->url->render($outputFormat)})";
×
85
    }
86

87
    /**
88
     * @return array<string, bool|int|float|string|array<mixed>|null>
89
     *
90
     * @internal
91
     */
92
    public function getArrayRepresentation(): array
2✔
93
    {
94
        return [
95
            'class' => $this->getShortClassName(),
2✔
96
            // We're using the term "uri" here to match the wording used in the specs:
97
            // https://www.w3.org/TR/CSS22/syndata.html#uri
98
            'uri' => $this->url->getArrayRepresentation(),
2✔
99
        ];
100
    }
101
}
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

© 2026 Coveralls, Inc