• 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

30.77
/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
use Sabberworm\CSS\ShortClassNameProvider;
13

14
use function Safe\preg_match;
15

16
/**
17
 * This class is a wrapper for quoted strings to distinguish them from keywords.
18
 *
19
 * `CSSString`s always output with double quotes.
20
 */
21
class CSSString extends PrimitiveValue
22
{
23
    use ShortClassNameProvider;
24

25
    /**
26
     * @var string
27
     */
28
    private $string;
29

30
    /**
31
     * @param int<1, max>|null $lineNumber
32
     */
33
    public function __construct(string $string, ?int $lineNumber = null)
8✔
34
    {
35
        $this->string = $string;
8✔
36
        parent::__construct($lineNumber);
8✔
37
    }
8✔
38

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

81
    public function setString(string $string): void
1✔
82
    {
83
        $this->string = $string;
1✔
84
    }
1✔
85

86
    public function getString(): string
2✔
87
    {
88
        return $this->string;
2✔
89
    }
90

91
    /**
92
     * @return non-empty-string
93
     */
94
    public function render(OutputFormat $outputFormat): string
×
95
    {
UNCOV
96
        $string = \addslashes($this->string);
×
UNCOV
97
        $string = \str_replace("\n", '\\A', $string);
×
UNCOV
98
        return $outputFormat->getStringQuotingType() . $string . $outputFormat->getStringQuotingType();
×
99
    }
100

101
    /**
102
     * @return array<string, bool|int|float|string|array<mixed>|null>
103
     *
104
     * @internal
105
     */
106
    public function getArrayRepresentation(): array
2✔
107
    {
108
        return [
109
            'class' => $this->getShortClassName(),
2✔
110
            // We're using the term "contents" here to make the difference to the class more clear.
111
            'contents' => $this->string,
2✔
112
        ];
113
    }
114
}
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