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

MyIntervals / PHP-CSS-Parser / 14337970346

08 Apr 2025 03:49PM UTC coverage: 53.315%. Remained the same
14337970346

Pull #1231

github

web-flow
Merge 92b0ebfc3 into 4e107ac07
Pull Request #1231: [TASK] Add and implement `CSSElement` interface

949 of 1780 relevant lines covered (53.31%)

7.62 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\CommentContainer;
8
use Sabberworm\CSS\OutputFormat;
9
use Sabberworm\CSS\Position\Position;
10
use Sabberworm\CSS\Position\Positionable;
11
use Sabberworm\CSS\Value\CSSString;
12

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

26
    /**
27
     * @var CSSString
28
     */
29
    private $charset;
30

31
    /**
32
     * @param int<0, max> $lineNumber
33
     */
34
    public function __construct(CSSString $charset, int $lineNumber = 0)
×
35
    {
36
        $this->charset = $charset;
×
37
        $this->setPosition($lineNumber);
×
38
    }
×
39

40
    /**
41
     * @param string|CSSString $charset
42
     */
43
    public function setCharset($charset): void
×
44
    {
45
        $charset = $charset instanceof CSSString ? $charset : new CSSString($charset);
×
46
        $this->charset = $charset;
×
47
    }
×
48

49
    public function getCharset(): string
×
50
    {
51
        return $this->charset->getString();
×
52
    }
53

54
    /**
55
     * @return non-empty-string
56
     */
57
    public function render(OutputFormat $outputFormat): string
×
58
    {
59
        return "{$outputFormat->getFormatter()->comments($this)}@charset {$this->charset->render($outputFormat)};";
×
60
    }
61

62
    /**
63
     * @return non-empty-string
64
     */
65
    public function atRuleName(): string
×
66
    {
67
        return 'charset';
×
68
    }
69

70
    public function atRuleArgs(): CSSString
×
71
    {
72
        return $this->charset;
×
73
    }
74
}
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