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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Please also have a look at our

### Changed

- `Rule::setRule()` and `getRule()` are replaced with `setPropertyName()` and
`getPropertyName()` (#1506)
- `Selector` is now represented as a sequence of `Selector\Component` objects
which can be accessed via `getComponents()`, manipulated individually, or set
via `setComponents()` (#1478, #1486, #1487, #1488, #1494, #1496)
Expand All @@ -29,6 +31,9 @@ Please also have a look at our

### Deprecated

- `Rule::setRule()` and `getRule()` are deprecated and replaced with
`setPropertyName()` and `getPropertyName()` (#1506)

### Removed

### Fixed
Expand Down
50 changes: 35 additions & 15 deletions src/Rule/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use function Safe\preg_match;

/**
* `Rule`s just have a string key (the rule) and a 'Value'.
* `Rule`s just have a string key (the property name) and a 'Value'.
*
* In CSS, `Rule`s are expressed as follows: “key: value[0][0] value[0][1], value[1][0] value[1][1];”
*/
Expand All @@ -32,7 +32,7 @@ class Rule implements Commentable, CSSElement, Positionable
/**
* @var non-empty-string
*/
private $rule;
private $propertyName;

/**
* @var RuleValueList|string|null
Expand All @@ -45,13 +45,13 @@ class Rule implements Commentable, CSSElement, Positionable
private $isImportant = false;

/**
* @param non-empty-string $rule
* @param non-empty-string $propertyName
* @param int<1, max>|null $lineNumber
* @param int<0, max>|null $columnNumber
*/
public function __construct(string $rule, ?int $lineNumber = null, ?int $columnNumber = null)
public function __construct(string $propertyName, ?int $lineNumber = null, ?int $columnNumber = null)
{
$this->rule = $rule;
$this->propertyName = $propertyName;
$this->setPosition($lineNumber, $columnNumber);
}

Expand All @@ -75,7 +75,7 @@ public static function parse(ParserState $parserState, array $commentsBeforeRule
$parserState->consumeWhiteSpace($comments);
$rule->setComments($comments);
$parserState->consume(':');
$value = Value::parseValue($parserState, self::listDelimiterForRule($rule->getRule()));
$value = Value::parseValue($parserState, self::getDelimitersForPropertyValue($rule->getRule()));
$rule->setValue($value);
$parserState->consumeWhiteSpace();
if ($parserState->comes('!')) {
Expand All @@ -97,17 +97,17 @@ public static function parse(ParserState $parserState, array $commentsBeforeRule
* The first item is the innermost separator (or, put another way, the highest-precedence operator).
* The sequence continues to the outermost separator (or lowest-precedence operator).
*
* @param non-empty-string $rule
* @param non-empty-string $propertyName
*
* @return list<non-empty-string>
*/
private static function listDelimiterForRule(string $rule): array
private static function getDelimitersForPropertyValue(string $propertyName): array
{
if (preg_match('/^font($|-)/', $rule) === 1) {
if (preg_match('/^font($|-)/', $propertyName) === 1) {
return [',', '/', ' '];
}

switch ($rule) {
switch ($propertyName) {
case 'src':
return [' ', ','];
default:
Expand All @@ -116,19 +116,39 @@ private static function listDelimiterForRule(string $rule): array
}

/**
* @param non-empty-string $rule
* @param non-empty-string $propertyName
*/
public function setRule(string $rule): void
public function setPropertyName(string $propertyName): void
{
$this->rule = $rule;
$this->propertyName = $propertyName;
}

/**
* @return non-empty-string
*/
public function getPropertyName(): string
{
return $this->propertyName;
}

/**
* @param non-empty-string $propertyName
*
* @deprecated in v9.2, will be removed in v10.0; use `setPropertyName()` instead.
*/
public function setRule(string $propertyName): void
{
$this->propertyName = $propertyName;
}

/**
* @return non-empty-string
*
* @deprecated in v9.2, will be removed in v10.0; use `getPropertyName()` instead.
*/
public function getRule(): string
{
return $this->rule;
return $this->propertyName;
}

/**
Expand Down Expand Up @@ -186,7 +206,7 @@ public function getIsImportant(): bool
public function render(OutputFormat $outputFormat): string
{
$formatter = $outputFormat->getFormatter();
$result = "{$formatter->comments($this)}{$this->rule}:{$formatter->spaceAfterRuleName()}";
$result = "{$formatter->comments($this)}{$this->propertyName}:{$formatter->spaceAfterRuleName()}";
if ($this->value instanceof Value) { // Can also be a ValueList
$result .= $this->value->render($outputFormat);
} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Value/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ValueTest extends TestCase
/**
* the default set of delimiters for parsing most values
*
* @see \Sabberworm\CSS\Rule\Rule::listDelimiterForRule
* @see \Sabberworm\CSS\Rule\Rule::getDelimitersForPropertyValue
*/
private const DEFAULT_DELIMITERS = [',', ' ', '/'];

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Value/ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ValueTest extends TestCase
/**
* the default set of delimiters for parsing most values
*
* @see \Sabberworm\CSS\Rule\Rule::listDelimiterForRule
* @see \Sabberworm\CSS\Rule\Rule::getDelimitersForPropertyValue
*/
private const DEFAULT_DELIMITERS = [',', ' ', '/'];

Expand Down