Skip to content
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
12 changes: 8 additions & 4 deletions src/CSSList/CSSList.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
abstract class CSSList implements Renderable, Commentable
{
/**
* @var array<array-key, Comment> $aComments
* @var array<array-key, Comment>
*/
protected $aComments;

Expand All @@ -57,10 +57,10 @@ public function __construct($iLineNo = 0)
}

/**
* @throws SourceException
* @throws UnexpectedTokenException
*
* @return void
*
* @throws UnexpectedTokenException
* @throws SourceException
*/
public static function parseList(ParserState $oParserState, CSSList $oList)
{
Expand Down Expand Up @@ -451,6 +451,8 @@ public function getContents()

/**
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function addComments(array $aComments)
{
Expand All @@ -467,6 +469,8 @@ public function getComments()

/**
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function setComments(array $aComments)
{
Expand Down
10 changes: 7 additions & 3 deletions src/Comment/Commentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
interface Commentable
{
/**
* @param array $aComments Array of comments.
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function addComments(array $aComments);

/**
* @return array
* @return array<array-key, Comment>
*/
public function getComments();

/**
* @param array $aComments Array containing Comment objects.
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function setComments(array $aComments);
}
17 changes: 17 additions & 0 deletions src/Property/CSSNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sabberworm\CSS\Property;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\OutputFormat;

/**
Expand All @@ -15,6 +16,9 @@ class CSSNamespace implements AtRule

private $iLineNo;

/**
* @var array<array-key, Comment>
*/
protected $aComments;

public function __construct($mUrl, $sPrefix = null, $iLineNo = 0)
Expand Down Expand Up @@ -89,16 +93,29 @@ public function atRuleArgs()
return $aResult;
}

/**
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function addComments(array $aComments)
{
$this->aComments = array_merge($this->aComments, $aComments);
}

/**
* @return array<array-key, Comment>
*/
public function getComments()
{
return $this->aComments;
}

/**
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function setComments(array $aComments)
{
$this->aComments = $aComments;
Expand Down
16 changes: 15 additions & 1 deletion src/Property/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sabberworm\CSS\Property;

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

Expand All @@ -26,7 +27,7 @@ class Import implements AtRule
protected $iLineNo;

/**
* @var array
* @var array<array-key, Comment>
*/
protected $aComments;

Expand Down Expand Up @@ -97,16 +98,29 @@ public function atRuleArgs()
return $aResult;
}

/**
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function addComments(array $aComments)
{
$this->aComments = array_merge($this->aComments, $aComments);
}

/**
* @return array<array-key, Comment>
*/
public function getComments()
{
return $this->aComments;
}

/**
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function setComments(array $aComments)
{
$this->aComments = $aComments;
Expand Down
29 changes: 29 additions & 0 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,30 @@ class Selector
)$
/ux';

/**
* @var string
*/
private $sSelector;

/**
* @var int|null
*/
private $iSpecificity;

/**
* @param string $sSelector
*
* @return bool
*/
public static function isValid($sSelector)
{
return preg_match(static::SELECTOR_VALIDATION_RX, $sSelector);
}

/**
* @param string $sSelector
* @param bool $bCalculateSpecificity
*/
public function __construct($sSelector, $bCalculateSpecificity = false)
{
$this->setSelector($sSelector);
Expand All @@ -77,22 +92,36 @@ public function __construct($sSelector, $bCalculateSpecificity = false)
}
}

/**
* @return string
*/
public function getSelector()
{
return $this->sSelector;
}

/**
* @param string $sSelector
*
* @return void
*/
public function setSelector($sSelector)
{
$this->sSelector = trim($sSelector);
$this->iSpecificity = null;
}

/**
* @return string
*/
public function __toString()
{
return $this->getSelector();
}

/**
* @return int
*/
public function getSpecificity()
{
if ($this->iSpecificity === null) {
Expand Down
14 changes: 11 additions & 3 deletions src/RuleSet/RuleSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sabberworm\CSS\RuleSet;

use Sabberworm\CSS\Comment\Comment;
use Sabberworm\CSS\Comment\Commentable;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parsing\ParserState;
Expand All @@ -19,6 +20,9 @@ abstract class RuleSet implements Renderable, Commentable

protected $iLineNo;

/**
* @var array<array-key, Comment>
*/
protected $aComments;

public function __construct($iLineNo = 0)
Expand Down Expand Up @@ -265,23 +269,27 @@ public function render(OutputFormat $oOutputFormat)
}

/**
* @param array $aComments Array of comments.
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function addComments(array $aComments)
{
$this->aComments = array_merge($this->aComments, $aComments);
}

/**
* @return array
* @return array<array-key, Comment>
*/
public function getComments()
{
return $this->aComments;
}

/**
* @param array $aComments Array containing Comment objects.
* @param array<array-key, Comment> $aComments
*
* @return void
*/
public function setComments(array $aComments)
{
Expand Down