Skip to content

Commit ebbb247

Browse files
committed
[TASK] Rename Rule::$rule to Rule::$propertyName
This has become a misnomer. Rules are the outer enclosing blocks. Deprecate the existing setters and getters and add new ones. (The name of the `Rule` class itself is also a misnomer.) Ref: https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/CSS_Declaration
1 parent 252bbe1 commit ebbb247

2 files changed

Lines changed: 39 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Please also have a look at our
1818

1919
### Changed
2020

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

3032
### Deprecated
3133

34+
- `Rule::setRule()` and `getRule()` are deprecated and replaced with
35+
`setPropertyName()` and `getPropertyName()` (#1506)
36+
3237
### Removed
3338

3439
### Fixed

src/Rule/Rule.php

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use function Safe\preg_match;
2121

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

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

4747
/**
48-
* @param non-empty-string $rule
48+
* @param non-empty-string $propertyName
4949
* @param int<1, max>|null $lineNumber
5050
* @param int<0, max>|null $columnNumber
5151
*/
52-
public function __construct(string $rule, ?int $lineNumber = null, ?int $columnNumber = null)
52+
public function __construct(string $propertyName, ?int $lineNumber = null, ?int $columnNumber = null)
5353
{
54-
$this->rule = $rule;
54+
$this->propertyName = $propertyName;
5555
$this->setPosition($lineNumber, $columnNumber);
5656
}
5757

@@ -97,17 +97,17 @@ public static function parse(ParserState $parserState, array $commentsBeforeRule
9797
* The first item is the innermost separator (or, put another way, the highest-precedence operator).
9898
* The sequence continues to the outermost separator (or lowest-precedence operator).
9999
*
100-
* @param non-empty-string $rule
100+
* @param non-empty-string $propertyName
101101
*
102102
* @return list<non-empty-string>
103103
*/
104-
private static function listDelimiterForRule(string $rule): array
104+
private static function listDelimiterForRule(string $propertyName): array
105105
{
106-
if (preg_match('/^font($|-)/', $rule) === 1) {
106+
if (preg_match('/^font($|-)/', $propertyName) === 1) {
107107
return [',', '/', ' '];
108108
}
109109

110-
switch ($rule) {
110+
switch ($propertyName) {
111111
case 'src':
112112
return [' ', ','];
113113
default:
@@ -116,19 +116,39 @@ private static function listDelimiterForRule(string $rule): array
116116
}
117117

118118
/**
119-
* @param non-empty-string $rule
119+
* @param non-empty-string $propertyName
120120
*/
121-
public function setRule(string $rule): void
121+
public function setPropertyName(string $propertyName): void
122122
{
123-
$this->rule = $rule;
123+
$this->propertyName = $propertyName;
124124
}
125125

126126
/**
127127
* @return non-empty-string
128128
*/
129+
public function getPropertyName(): string
130+
{
131+
return $this->propertyName;
132+
}
133+
134+
/**
135+
* @param non-empty-string $propertyName
136+
*
137+
* @deprecated in v9.2, will be removed in v10.0; use `setPropertyName()` instead.
138+
*/
139+
public function setRule(string $propertyName): void
140+
{
141+
$this->propertyName = $propertyName;
142+
}
143+
144+
/**
145+
* @return non-empty-string
146+
*
147+
* @deprecated in v9.2, will be removed in v10.0; use `getPropertyName()` instead.
148+
*/
129149
public function getRule(): string
130150
{
131-
return $this->rule;
151+
return $this->propertyName;
132152
}
133153

134154
/**
@@ -186,7 +206,7 @@ public function getIsImportant(): bool
186206
public function render(OutputFormat $outputFormat): string
187207
{
188208
$formatter = $outputFormat->getFormatter();
189-
$result = "{$formatter->comments($this)}{$this->rule}:{$formatter->spaceAfterRuleName()}";
209+
$result = "{$formatter->comments($this)}{$this->propertyName}:{$formatter->spaceAfterRuleName()}";
190210
if ($this->value instanceof Value) { // Can also be a ValueList
191211
$result .= $this->value->render($outputFormat);
192212
} else {

0 commit comments

Comments
 (0)