Skip to content

Commit c93a78c

Browse files
committed
[TASK] Add CSSElement interface
1 parent 4e107ac commit c93a78c

File tree

7 files changed

+29
-8
lines changed

7 files changed

+29
-8
lines changed

src/CSSElement.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sabberworm\CSS;
6+
7+
/**
8+
* Represents any entity in the CSS that is encapsulated by a class.
9+
*
10+
* Its primary purpose is to provide a type for use with `Document::getAllValues()`
11+
* when a subset of values from a particular part of the document is required.
12+
*
13+
* Thus, elements which don't contain `Value`s (such as statement at-rules) don't need to implement this.
14+
*
15+
* It extends `Renderable` because every element is renderable.
16+
*/
17+
interface CSSElement extends Renderable {}

src/CSSList/CSSBlockList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Sabberworm\CSS\CSSList;
66

7+
use Sabberworm\CSS\CSSElement;
78
use Sabberworm\CSS\Property\Selector;
89
use Sabberworm\CSS\Rule\Rule;
910
use Sabberworm\CSS\RuleSet\DeclarationBlock;
@@ -75,7 +76,7 @@ public function getAllRuleSets(): array
7576
}
7677

7778
/**
78-
* @param CSSList|Rule|RuleSet|Value $element
79+
* @param CSSElement|string $element
7980
* @param list<Value> $result
8081
*/
8182
protected function allValues(

src/CSSList/CSSList.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Sabberworm\CSS\CSSList;
66

77
use Sabberworm\CSS\Comment\CommentContainer;
8+
use Sabberworm\CSS\CSSElement;
89
use Sabberworm\CSS\OutputFormat;
910
use Sabberworm\CSS\Parsing\ParserState;
1011
use Sabberworm\CSS\Parsing\SourceException;
@@ -34,7 +35,7 @@
3435
* Note that `CSSListItem` extends both `Commentable` and `Renderable`,
3536
* so those interfaces must also be implemented by concrete subclasses.
3637
*/
37-
abstract class CSSList implements CSSListItem, Positionable
38+
abstract class CSSList implements CSSElement, CSSListItem, Positionable
3839
{
3940
use CommentContainer;
4041
use Position;

src/CSSList/Document.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Sabberworm\CSS\CSSList;
66

7+
use Sabberworm\CSS\CSSElement;
78
use Sabberworm\CSS\OutputFormat;
89
use Sabberworm\CSS\Parsing\ParserState;
910
use Sabberworm\CSS\Parsing\SourceException;
@@ -33,7 +34,7 @@ public static function parse(ParserState $parserState): Document
3334
/**
3435
* Returns all `Value` objects found recursively in `Rule`s in the tree.
3536
*
36-
* @param CSSList|RuleSet|string $element
37+
* @param CSSElement|string $element
3738
* the `CSSList` or `RuleSet` to start the search from (defaults to the whole document).
3839
* If a string is given, it is used as rule name filter.
3940
* @param bool $searchInFunctionArguments whether to also return Value objects used as Function arguments.

src/Rule/Rule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
use Sabberworm\CSS\Comment\Comment;
88
use Sabberworm\CSS\Comment\Commentable;
99
use Sabberworm\CSS\Comment\CommentContainer;
10+
use Sabberworm\CSS\CSSElement;
1011
use Sabberworm\CSS\OutputFormat;
1112
use Sabberworm\CSS\Parsing\ParserState;
1213
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
1314
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1415
use Sabberworm\CSS\Position\Position;
1516
use Sabberworm\CSS\Position\Positionable;
16-
use Sabberworm\CSS\Renderable;
1717
use Sabberworm\CSS\Value\RuleValueList;
1818
use Sabberworm\CSS\Value\Value;
1919

@@ -22,7 +22,7 @@
2222
*
2323
* In CSS, `Rule`s are expressed as follows: “key: value[0][0] value[0][1], value[1][0] value[1][1];”
2424
*/
25-
class Rule implements Commentable, Positionable, Renderable
25+
class Rule implements Commentable, CSSElement, Positionable
2626
{
2727
use CommentContainer;
2828
use Position;

src/RuleSet/RuleSet.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Sabberworm\CSS\RuleSet;
66

77
use Sabberworm\CSS\Comment\CommentContainer;
8+
use Sabberworm\CSS\CSSElement;
89
use Sabberworm\CSS\CSSList\CSSListItem;
910
use Sabberworm\CSS\OutputFormat;
1011
use Sabberworm\CSS\Parsing\ParserState;
@@ -26,7 +27,7 @@
2627
* Note that `CSSListItem` extends both `Commentable` and `Renderable`,
2728
* so those interfaces must also be implemented by concrete subclasses.
2829
*/
29-
abstract class RuleSet implements CSSListItem, Positionable
30+
abstract class RuleSet implements CSSElement, CSSListItem, Positionable
3031
{
3132
use CommentContainer;
3233
use Position;

src/Value/Value.php

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

55
namespace Sabberworm\CSS\Value;
66

7+
use Sabberworm\CSS\CSSElement;
78
use Sabberworm\CSS\Parsing\ParserState;
89
use Sabberworm\CSS\Parsing\SourceException;
910
use Sabberworm\CSS\Parsing\UnexpectedEOFException;
1011
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1112
use Sabberworm\CSS\Position\Position;
1213
use Sabberworm\CSS\Position\Positionable;
13-
use Sabberworm\CSS\Renderable;
1414

1515
/**
1616
* Abstract base class for specific classes of CSS values: `Size`, `Color`, `CSSString` and `URL`, and another
1717
* abstract subclass `ValueList`.
1818
*/
19-
abstract class Value implements Positionable, Renderable
19+
abstract class Value implements CSSElement, Positionable
2020
{
2121
use Position;
2222

0 commit comments

Comments
 (0)