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

MyIntervals / PHP-CSS-Parser / 13562750149

27 Feb 2025 09:09AM UTC coverage: 54.784%. Remained the same
13562750149

push

github

web-flow
[TASK] Deprecate `__toString()` (#1006)

Part of #998

1042 of 1902 relevant lines covered (54.78%)

12.12 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 $oURL;
22

23
    /**
24
     * @param int<0, max> $lineNumber
25
     */
26
    public function __construct(CSSString $oURL, $lineNumber = 0)
14✔
27
    {
28
        parent::__construct($lineNumber);
14✔
29
        $this->oURL = $oURL;
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
        $oAnchor = $parserState->anchor();
14✔
42
        $identifier = '';
14✔
43
        for ($i = 0; $i < 3; $i++) {
14✔
44
            $sChar = $parserState->parseCharacter(true);
14✔
45
            if ($sChar === null) {
14✔
46
                break;
4✔
47
            }
48
            $identifier .= $sChar;
11✔
49
        }
50
        $bUseUrl = $parserState->streql($identifier, 'url');
14✔
51
        if ($bUseUrl) {
14✔
52
            $parserState->consumeWhiteSpace();
11✔
53
            $parserState->consume('(');
11✔
54
        } else {
55
            $oAnchor->backtrack();
4✔
56
        }
57
        $parserState->consumeWhiteSpace();
14✔
58
        $result = new URL(CSSString::parse($parserState), $parserState->currentLine());
14✔
59
        if ($bUseUrl) {
14✔
60
            $parserState->consumeWhiteSpace();
11✔
61
            $parserState->consume(')');
11✔
62
        }
63
        return $result;
14✔
64
    }
65

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

71
    /**
72
     * @return CSSString
73
     */
74
    public function getURL()
×
75
    {
76
        return $this->oURL;
×
77
    }
78

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

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