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

MyIntervals / PHP-CSS-Parser / 13887209533

16 Mar 2025 08:42PM UTC coverage: 56.036%. Remained the same
13887209533

push

github

web-flow
[TASK] Add native type declarations for `Charset` (#1178)

Part of #811

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

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

0.0
/src/Property/Charset.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Sabberworm\CSS\Property;
6

7
use Sabberworm\CSS\Comment\Comment;
8
use Sabberworm\CSS\OutputFormat;
9
use Sabberworm\CSS\Value\CSSString;
10

11
/**
12
 * Class representing an `@charset` rule.
13
 *
14
 * The following restrictions apply:
15
 * - May not be found in any CSSList other than the Document.
16
 * - May only appear at the very top of a Document’s contents.
17
 * - Must not appear more than once.
18
 */
19
class Charset implements AtRule
20
{
21
    /**
22
     * @var CSSString
23
     */
24
    private $charset;
25

26
    /**
27
     * @var int<0, max>
28
     *
29
     * @internal since 8.8.0
30
     */
31
    protected $lineNumber;
32

33
    /**
34
     * @var list<Comment>
35
     *
36
     * @internal since 8.8.0
37
     */
38
    protected $comments = [];
39

40
    /**
41
     * @param int<0, max> $lineNumber
42
     */
43
    public function __construct(CSSString $charset, int $lineNumber = 0)
×
44
    {
45
        $this->charset = $charset;
×
46
        $this->lineNumber = $lineNumber;
×
47
    }
×
48

49
    /**
50
     * @return int<0, max>
51
     */
52
    public function getLineNo(): int
×
53
    {
54
        return $this->lineNumber;
×
55
    }
56

57
    /**
58
     * @param string|CSSString $charset
59
     */
60
    public function setCharset($charset): void
×
61
    {
62
        $charset = $charset instanceof CSSString ? $charset : new CSSString($charset);
×
63
        $this->charset = $charset;
×
64
    }
×
65

NEW
66
    public function getCharset(): string
×
67
    {
68
        return $this->charset->getString();
×
69
    }
70

71
    /**
72
     * @deprecated in V8.8.0, will be removed in V9.0.0. Use `render` instead.
73
     */
74
    public function __toString(): string
×
75
    {
76
        return $this->render(new OutputFormat());
×
77
    }
78

79
    public function render(OutputFormat $outputFormat): string
×
80
    {
81
        return "{$outputFormat->getFormatter()->comments($this)}@charset {$this->charset->render($outputFormat)};";
×
82
    }
83

84
    /**
85
     * @return non-empty-string
86
     */
87
    public function atRuleName(): string
×
88
    {
89
        return 'charset';
×
90
    }
91

NEW
92
    public function atRuleArgs(): CSSString
×
93
    {
94
        return $this->charset;
×
95
    }
96

97
    /**
98
     * @param list<Comment> $comments
99
     */
100
    public function addComments(array $comments): void
×
101
    {
102
        $this->comments = \array_merge($this->comments, $comments);
×
103
    }
×
104

105
    /**
106
     * @return list<Comment>
107
     */
108
    public function getComments(): array
×
109
    {
110
        return $this->comments;
×
111
    }
112

113
    /**
114
     * @param list<Comment> $comments
115
     */
116
    public function setComments(array $comments): void
×
117
    {
118
        $this->comments = $comments;
×
119
    }
×
120
}
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