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

MyIntervals / PHP-CSS-Parser / 13839965065

13 Mar 2025 04:41PM UTC coverage: 55.455%. Remained the same
13839965065

Pull #1163

github

web-flow
Merge c254128a4 into 7e688fc24
Pull Request #1163: [TASK] Add native type declarations in `URL`

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

1042 of 1879 relevant lines covered (55.46%)

12.4 hits per line

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

78.13
/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

13
/**
14
 * This class represents URLs in CSS. `URL`s always output in `URL("")` notation.
15
 */
16
class URL extends PrimitiveValue
17
{
18
    /**
19
     * @var CSSString
20
     */
21
    private $url;
22

23
    /**
24
     * @param int<0, max> $lineNumber
25
     */
26
    public function __construct(CSSString $url, int $lineNumber = 0)
14✔
27
    {
28
        parent::__construct($lineNumber);
14✔
29
        $this->url = $url;
14✔
30
    }
14✔
31

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

66
    public function setURL(CSSString $url): void
×
67
    {
68
        $this->url = $url;
×
69
    }
×
70

NEW
71
    public function getURL(): CSSString
×
72
    {
73
        return $this->url;
×
74
    }
75

76
    /**
77
     * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
78
     */
79
    public function __toString(): string
×
80
    {
81
        return $this->render(new OutputFormat());
×
82
    }
83

84
    public function render(OutputFormat $outputFormat): string
10✔
85
    {
86
        return "url({$this->url->render($outputFormat)})";
10✔
87
    }
88
}
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