Debian Codegraph @

vendor/sabberworm/php-css-parser/src/Comment/Comment.php

raw
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Sabberworm\CSS\Comment;
6
7 use Sabberworm\CSS\OutputFormat;
8 use Sabberworm\CSS\Position\Position;
9 use Sabberworm\CSS\Position\Positionable;
10 use Sabberworm\CSS\Renderable;
11 use Sabberworm\CSS\ShortClassNameProvider;
12
13 class Comment implements Positionable, Renderable
14 {
15 use Position;
16 use ShortClassNameProvider;
17
18 /**
19 * @var string
20 *
21 * @internal since 8.8.0
22 */
23 protected $commentText;
24
25 /**
26 * @param int<1, max>|null $lineNumber
27 */
28 public function __construct(string $commentText = '', ?int $lineNumber = null)
29 {
30 $this->commentText = $commentText;
31 $this->setPosition($lineNumber);
32 }
33
34 public function getComment(): string
35 {
36 return $this->commentText;
37 }
38
39 public function setComment(string $commentText): void
40 {
41 $this->commentText = $commentText;
42 }
43
44 /**
45 * @return non-empty-string
46 */
47 public function render(OutputFormat $outputFormat): string
48 {
49 return '/*' . $this->commentText . '*/';
50 }
51
52 /**
53 * @return array<string, bool|int|float|string|array<mixed>|null>
54 *
55 * @internal
56 */
57 public function getArrayRepresentation(): array
58 {
59 return [
60 'class' => $this->getShortClassName(),
61 // "contents" is the term used in the W3C specs:
62 // https://www.w3.org/TR/CSS22/syndata.html#comments
63 'contents' => $this->commentText,
64 ];
65 }
66 }