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

MyIntervals / PHP-CSS-Parser / 13887271791

16 Mar 2025 08:52PM UTC coverage: 56.036%. Remained the same
13887271791

Pull #818

github

web-flow
Merge af1b6618e into 4312c56fc
Pull Request #818: [TASK] Use native types for all constructor parameters

4 of 7 new or added lines in 7 files covered. (57.14%)

3 existing lines in 1 file now uncovered.

1049 of 1872 relevant lines covered (56.04%)

12.69 hits per line

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

86.84
/src/Value/CSSString.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 is a wrapper for quoted strings to distinguish them from keywords.
15
 *
16
 * `CSSString`s always output with double quotes.
17
 */
18
class CSSString extends PrimitiveValue
19
{
20
    /**
21
     * @var string
22
     */
23
    private $string;
24

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

34
    /**
35
     * @throws SourceException
36
     * @throws UnexpectedEOFException
37
     * @throws UnexpectedTokenException
38
     *
39
     * @internal since V8.8.0
40
     */
41
    public static function parse(ParserState $parserState): CSSString
22✔
42
    {
43
        $begin = $parserState->peek();
22✔
44
        $quote = null;
22✔
45
        if ($begin === "'") {
22✔
46
            $quote = "'";
10✔
47
        } elseif ($begin === '"') {
17✔
48
            $quote = '"';
15✔
49
        }
50
        if ($quote !== null) {
22✔
51
            $parserState->consume($quote);
20✔
52
        }
53
        $result = '';
22✔
54
        $content = null;
22✔
55
        if ($quote === null) {
22✔
56
            // Unquoted strings end in whitespace or with braces, brackets, parentheses
57
            while (\preg_match('/[\\s{}()<>\\[\\]]/isu', $parserState->peek()) !== 1) {
5✔
58
                $result .= $parserState->parseCharacter(false);
5✔
59
            }
60
        } else {
61
            while (!$parserState->comes($quote)) {
20✔
62
                $content = $parserState->parseCharacter(false);
20✔
63
                if ($content === null) {
20✔
UNCOV
64
                    throw new SourceException(
×
65
                        "Non-well-formed quoted string {$parserState->peek(3)}",
×
66
                        $parserState->currentLine()
×
67
                    );
68
                }
69
                $result .= $content;
20✔
70
            }
71
            $parserState->consume($quote);
20✔
72
        }
73
        return new CSSString($result, $parserState->currentLine());
22✔
74
    }
75

76
    /**
77
     * @param string $string
78
     */
79
    public function setString($string): void
1✔
80
    {
81
        $this->string = $string;
1✔
82
    }
1✔
83

84
    /**
85
     * @return string
86
     */
87
    public function getString()
8✔
88
    {
89
        return $this->string;
8✔
90
    }
91

92
    /**
93
     * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
94
     */
UNCOV
95
    public function __toString(): string
×
96
    {
UNCOV
97
        return $this->render(new OutputFormat());
×
98
    }
99

100
    public function render(OutputFormat $outputFormat): string
13✔
101
    {
102
        $string = \addslashes($this->string);
13✔
103
        $string = \str_replace("\n", '\\A', $string);
13✔
104
        return $outputFormat->getStringQuotingType() . $string . $outputFormat->getStringQuotingType();
13✔
105
    }
106
}
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