Skip to content

[TASK] Use CommentContainer trait to implement Commentable #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 2 additions & 32 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Sabberworm\CSS\CSSList;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\Commentable;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why the fixer didn't complain about this unsed use (CSSListItem extends Commentable, as of #1212, but when that change was made, Commentable was no longer directly referenced in this file).

use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\SourceException;
Expand Down Expand Up @@ -36,12 +35,7 @@
*/
abstract class CSSList implements CSSListItem
{
/**
* @var list<Comment>
*
* @internal since 8.8.0
*/
protected $comments = [];
use CommentContainer;

/**
* @var array<int<0, max>, CSSListItem>
Expand Down Expand Up @@ -444,28 +438,4 @@ public function getContents(): array
{
return $this->contents;
}

/**
* @param list<Comment> $comments
*/
public function addComments(array $comments): void
{
$this->comments = \array_merge($this->comments, $comments);
}

/**
* @return list<Comment>
*/
public function getComments(): array
{
return $this->comments;
}

/**
* @param list<Comment> $comments
*/
public function setComments(array $comments): void
{
$this->comments = $comments;
}
}
35 changes: 3 additions & 32 deletions src/Property/CSSNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sabberworm\CSS\Property;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Value\CSSString;
use Sabberworm\CSS\Value\URL;
Expand All @@ -14,6 +14,8 @@
*/
class CSSNamespace implements AtRule
{
use CommentContainer;

/**
* @var CSSString|URL
*/
Expand All @@ -29,13 +31,6 @@ class CSSNamespace implements AtRule
*/
private $lineNumber;

/**
* @var list<Comment>
*
* @internal since 8.8.0
*/
protected $comments = [];

/**
* @param CSSString|URL $url
* @param int<0, max> $lineNumber
Expand Down Expand Up @@ -109,28 +104,4 @@ public function atRuleArgs(): array
}
return $result;
}

/**
* @param list<Comment> $comments
*/
public function addComments(array $comments): void
{
$this->comments = \array_merge($this->comments, $comments);
}

/**
* @return list<Comment>
*/
public function getComments(): array
{
return $this->comments;
}

/**
* @param list<Comment> $comments
*/
public function setComments(array $comments): void
{
$this->comments = $comments;
}
}
35 changes: 3 additions & 32 deletions src/Property/Charset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sabberworm\CSS\Property;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Value\CSSString;

Expand All @@ -18,6 +18,8 @@
*/
class Charset implements AtRule
{
use CommentContainer;

/**
* @var CSSString
*/
Expand All @@ -30,13 +32,6 @@ class Charset implements AtRule
*/
protected $lineNumber;

/**
* @var list<Comment>
*
* @internal since 8.8.0
*/
protected $comments = [];

/**
* @param int<0, max> $lineNumber
*/
Expand Down Expand Up @@ -88,28 +83,4 @@ public function atRuleArgs(): CSSString
{
return $this->charset;
}

/**
* @param list<Comment> $comments
*/
public function addComments(array $comments): void
{
$this->comments = \array_merge($this->comments, $comments);
}

/**
* @return list<Comment>
*/
public function getComments(): array
{
return $this->comments;
}

/**
* @param list<Comment> $comments
*/
public function setComments(array $comments): void
{
$this->comments = $comments;
}
}
35 changes: 3 additions & 32 deletions src/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sabberworm\CSS\Property;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Value\URL;

Expand All @@ -13,6 +13,8 @@
*/
class Import implements AtRule
{
use CommentContainer;

/**
* @var URL
*/
Expand All @@ -30,13 +32,6 @@ class Import implements AtRule
*/
protected $lineNumber;

/**
* @var list<Comment>
*
* @internal since 8.8.0
*/
protected $comments = [];

/**
* @param int<0, max> $lineNumber
*/
Expand Down Expand Up @@ -95,30 +90,6 @@ public function atRuleArgs(): array
return $result;
}

/**
* @param list<Comment> $comments
*/
public function addComments(array $comments): void
{
$this->comments = \array_merge($this->comments, $comments);
}

/**
* @return list<Comment>
*/
public function getComments(): array
{
return $this->comments;
}

/**
* @param list<Comment> $comments
*/
public function setComments(array $comments): void
{
$this->comments = $comments;
}

public function getMediaQuery(): ?string
{
return $this->mediaQuery;
Expand Down
34 changes: 3 additions & 31 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\Commentable;
use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
Expand All @@ -21,6 +22,8 @@
*/
class Rule implements Renderable, Commentable
{
use CommentContainer;

/**
* @var non-empty-string
*/
Expand Down Expand Up @@ -48,13 +51,6 @@ class Rule implements Renderable, Commentable
*/
protected $columnNumber;

/**
* @var list<Comment>
*
* @internal since 8.8.0
*/
protected $comments = [];

/**
* @param non-empty-string $rule
* @param int<0, max> $lineNumber
Expand Down Expand Up @@ -235,28 +231,4 @@ public function render(OutputFormat $outputFormat): string
$result .= ';';
return $result;
}

/**
* @param list<Comment> $comments
*/
public function addComments(array $comments): void
{
$this->comments = \array_merge($this->comments, $comments);
}

/**
* @return list<Comment>
*/
public function getComments(): array
{
return $this->comments;
}

/**
* @param list<Comment> $comments
*/
public function setComments(array $comments): void
{
$this->comments = $comments;
}
}
36 changes: 3 additions & 33 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

namespace Sabberworm\CSS\RuleSet;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\Commentable;
use Sabberworm\CSS\Comment\CommentContainer;
use Sabberworm\CSS\CSSList\CSSListItem;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
Expand All @@ -28,6 +27,8 @@
*/
abstract class RuleSet implements CSSListItem
{
use CommentContainer;

/**
* the rules in this rule set, using the property name as the key,
* with potentially multiple rules per property name.
Expand All @@ -43,13 +44,6 @@ abstract class RuleSet implements CSSListItem
*/
protected $lineNumber;

/**
* @var list<Comment>
*
* @internal since 8.8.0
*/
protected $comments = [];

/**
* @param int<0, max> $lineNumber
*/
Expand Down Expand Up @@ -299,28 +293,4 @@ protected function renderRules(OutputFormat $outputFormat): string

return $formatter->removeLastSemicolon($result);
}

/**
* @param list<Comment> $comments
*/
public function addComments(array $comments): void
{
$this->comments = \array_merge($this->comments, $comments);
}

/**
* @return list<Comment>
*/
public function getComments(): array
{
return $this->comments;
}

/**
* @param list<Comment> $comments
*/
public function setComments(array $comments): void
{
$this->comments = $comments;
}
}