Skip to content

Commit 8104f52

Browse files
authored
[TASK] Use CommentContainer trait to implement Commentable (#1217)
Closes #813.
1 parent ee07bde commit 8104f52

File tree

6 files changed

+17
-192
lines changed

6 files changed

+17
-192
lines changed

src/CSSList/CSSList.php

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Sabberworm\CSS\CSSList;
66

7-
use Sabberworm\CSS\Comment\Comment;
8-
use Sabberworm\CSS\Comment\Commentable;
7+
use Sabberworm\CSS\Comment\CommentContainer;
98
use Sabberworm\CSS\OutputFormat;
109
use Sabberworm\CSS\Parsing\ParserState;
1110
use Sabberworm\CSS\Parsing\SourceException;
@@ -36,12 +35,7 @@
3635
*/
3736
abstract class CSSList implements CSSListItem
3837
{
39-
/**
40-
* @var list<Comment>
41-
*
42-
* @internal since 8.8.0
43-
*/
44-
protected $comments = [];
38+
use CommentContainer;
4539

4640
/**
4741
* @var array<int<0, max>, CSSListItem>
@@ -444,28 +438,4 @@ public function getContents(): array
444438
{
445439
return $this->contents;
446440
}
447-
448-
/**
449-
* @param list<Comment> $comments
450-
*/
451-
public function addComments(array $comments): void
452-
{
453-
$this->comments = \array_merge($this->comments, $comments);
454-
}
455-
456-
/**
457-
* @return list<Comment>
458-
*/
459-
public function getComments(): array
460-
{
461-
return $this->comments;
462-
}
463-
464-
/**
465-
* @param list<Comment> $comments
466-
*/
467-
public function setComments(array $comments): void
468-
{
469-
$this->comments = $comments;
470-
}
471441
}

src/Property/CSSNamespace.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Sabberworm\CSS\Property;
66

7-
use Sabberworm\CSS\Comment\Comment;
7+
use Sabberworm\CSS\Comment\CommentContainer;
88
use Sabberworm\CSS\OutputFormat;
99
use Sabberworm\CSS\Value\CSSString;
1010
use Sabberworm\CSS\Value\URL;
@@ -14,6 +14,8 @@
1414
*/
1515
class CSSNamespace implements AtRule
1616
{
17+
use CommentContainer;
18+
1719
/**
1820
* @var CSSString|URL
1921
*/
@@ -29,13 +31,6 @@ class CSSNamespace implements AtRule
2931
*/
3032
private $lineNumber;
3133

32-
/**
33-
* @var list<Comment>
34-
*
35-
* @internal since 8.8.0
36-
*/
37-
protected $comments = [];
38-
3934
/**
4035
* @param CSSString|URL $url
4136
* @param int<0, max> $lineNumber
@@ -109,28 +104,4 @@ public function atRuleArgs(): array
109104
}
110105
return $result;
111106
}
112-
113-
/**
114-
* @param list<Comment> $comments
115-
*/
116-
public function addComments(array $comments): void
117-
{
118-
$this->comments = \array_merge($this->comments, $comments);
119-
}
120-
121-
/**
122-
* @return list<Comment>
123-
*/
124-
public function getComments(): array
125-
{
126-
return $this->comments;
127-
}
128-
129-
/**
130-
* @param list<Comment> $comments
131-
*/
132-
public function setComments(array $comments): void
133-
{
134-
$this->comments = $comments;
135-
}
136107
}

src/Property/Charset.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Sabberworm\CSS\Property;
66

7-
use Sabberworm\CSS\Comment\Comment;
7+
use Sabberworm\CSS\Comment\CommentContainer;
88
use Sabberworm\CSS\OutputFormat;
99
use Sabberworm\CSS\Value\CSSString;
1010

@@ -18,6 +18,8 @@
1818
*/
1919
class Charset implements AtRule
2020
{
21+
use CommentContainer;
22+
2123
/**
2224
* @var CSSString
2325
*/
@@ -30,13 +32,6 @@ class Charset implements AtRule
3032
*/
3133
protected $lineNumber;
3234

33-
/**
34-
* @var list<Comment>
35-
*
36-
* @internal since 8.8.0
37-
*/
38-
protected $comments = [];
39-
4035
/**
4136
* @param int<0, max> $lineNumber
4237
*/
@@ -88,28 +83,4 @@ public function atRuleArgs(): CSSString
8883
{
8984
return $this->charset;
9085
}
91-
92-
/**
93-
* @param list<Comment> $comments
94-
*/
95-
public function addComments(array $comments): void
96-
{
97-
$this->comments = \array_merge($this->comments, $comments);
98-
}
99-
100-
/**
101-
* @return list<Comment>
102-
*/
103-
public function getComments(): array
104-
{
105-
return $this->comments;
106-
}
107-
108-
/**
109-
* @param list<Comment> $comments
110-
*/
111-
public function setComments(array $comments): void
112-
{
113-
$this->comments = $comments;
114-
}
11586
}

src/Property/Import.php

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Sabberworm\CSS\Property;
66

7-
use Sabberworm\CSS\Comment\Comment;
7+
use Sabberworm\CSS\Comment\CommentContainer;
88
use Sabberworm\CSS\OutputFormat;
99
use Sabberworm\CSS\Value\URL;
1010

@@ -13,6 +13,8 @@
1313
*/
1414
class Import implements AtRule
1515
{
16+
use CommentContainer;
17+
1618
/**
1719
* @var URL
1820
*/
@@ -30,13 +32,6 @@ class Import implements AtRule
3032
*/
3133
protected $lineNumber;
3234

33-
/**
34-
* @var list<Comment>
35-
*
36-
* @internal since 8.8.0
37-
*/
38-
protected $comments = [];
39-
4035
/**
4136
* @param int<0, max> $lineNumber
4237
*/
@@ -95,30 +90,6 @@ public function atRuleArgs(): array
9590
return $result;
9691
}
9792

98-
/**
99-
* @param list<Comment> $comments
100-
*/
101-
public function addComments(array $comments): void
102-
{
103-
$this->comments = \array_merge($this->comments, $comments);
104-
}
105-
106-
/**
107-
* @return list<Comment>
108-
*/
109-
public function getComments(): array
110-
{
111-
return $this->comments;
112-
}
113-
114-
/**
115-
* @param list<Comment> $comments
116-
*/
117-
public function setComments(array $comments): void
118-
{
119-
$this->comments = $comments;
120-
}
121-
12293
public function getMediaQuery(): ?string
12394
{
12495
return $this->mediaQuery;

src/Rule/Rule.php

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Sabberworm\CSS\Comment\Comment;
88
use Sabberworm\CSS\Comment\Commentable;
9+
use Sabberworm\CSS\Comment\CommentContainer;
910
use Sabberworm\CSS\OutputFormat;
1011
use Sabberworm\CSS\Parsing\ParserState;
1112
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
@@ -21,6 +22,8 @@
2122
*/
2223
class Rule implements Renderable, Commentable
2324
{
25+
use CommentContainer;
26+
2427
/**
2528
* @var non-empty-string
2629
*/
@@ -48,13 +51,6 @@ class Rule implements Renderable, Commentable
4851
*/
4952
protected $columnNumber;
5053

51-
/**
52-
* @var list<Comment>
53-
*
54-
* @internal since 8.8.0
55-
*/
56-
protected $comments = [];
57-
5854
/**
5955
* @param non-empty-string $rule
6056
* @param int<0, max> $lineNumber
@@ -235,28 +231,4 @@ public function render(OutputFormat $outputFormat): string
235231
$result .= ';';
236232
return $result;
237233
}
238-
239-
/**
240-
* @param list<Comment> $comments
241-
*/
242-
public function addComments(array $comments): void
243-
{
244-
$this->comments = \array_merge($this->comments, $comments);
245-
}
246-
247-
/**
248-
* @return list<Comment>
249-
*/
250-
public function getComments(): array
251-
{
252-
return $this->comments;
253-
}
254-
255-
/**
256-
* @param list<Comment> $comments
257-
*/
258-
public function setComments(array $comments): void
259-
{
260-
$this->comments = $comments;
261-
}
262234
}

src/RuleSet/RuleSet.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace Sabberworm\CSS\RuleSet;
66

7-
use Sabberworm\CSS\Comment\Comment;
8-
use Sabberworm\CSS\Comment\Commentable;
7+
use Sabberworm\CSS\Comment\CommentContainer;
98
use Sabberworm\CSS\CSSList\CSSListItem;
109
use Sabberworm\CSS\OutputFormat;
1110
use Sabberworm\CSS\Parsing\ParserState;
@@ -28,6 +27,8 @@
2827
*/
2928
abstract class RuleSet implements CSSListItem
3029
{
30+
use CommentContainer;
31+
3132
/**
3233
* the rules in this rule set, using the property name as the key,
3334
* with potentially multiple rules per property name.
@@ -43,13 +44,6 @@ abstract class RuleSet implements CSSListItem
4344
*/
4445
protected $lineNumber;
4546

46-
/**
47-
* @var list<Comment>
48-
*
49-
* @internal since 8.8.0
50-
*/
51-
protected $comments = [];
52-
5347
/**
5448
* @param int<0, max> $lineNumber
5549
*/
@@ -299,28 +293,4 @@ protected function renderRules(OutputFormat $outputFormat): string
299293

300294
return $formatter->removeLastSemicolon($result);
301295
}
302-
303-
/**
304-
* @param list<Comment> $comments
305-
*/
306-
public function addComments(array $comments): void
307-
{
308-
$this->comments = \array_merge($this->comments, $comments);
309-
}
310-
311-
/**
312-
* @return list<Comment>
313-
*/
314-
public function getComments(): array
315-
{
316-
return $this->comments;
317-
}
318-
319-
/**
320-
* @param list<Comment> $comments
321-
*/
322-
public function setComments(array $comments): void
323-
{
324-
$this->comments = $comments;
325-
}
326296
}

0 commit comments

Comments
 (0)