Skip to content

Commit 6a0cfa1

Browse files
committed
[TASK] Have setPosition() implement fluent interface
This will aid writing tests for `RuleSet`. Note that the PHP type annotation cannot be `self` because an interface is involved and PHP 7 is still supported. Part of #974.
1 parent 8587712 commit 6a0cfa1

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CHANGELOG.md

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

3333
### Changed
3434

35+
- `setPosition()` (in `Rule` and other classes) now has fluent interface,
36+
returning itself (#1259)
3537
- `RuleSet::removeRule()` now only allows `Rule` as the parameter
3638
(implementing classes are `AtRuleSet` and `DeclarationBlock`);
3739
use `removeMatchingRules()` or `removeAllRules()` for other functions (#1255)

src/Position/Position.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ public function getColNo(): int
5858
/**
5959
* @param int<0, max>|null $lineNumber
6060
* @param int<0, max>|null $columnNumber
61+
*
62+
* @return $this fluent interface
6163
*/
62-
public function setPosition(?int $lineNumber, ?int $columnNumber = null): void
64+
public function setPosition(?int $lineNumber, ?int $columnNumber = null): Positionable
6365
{
6466
// The conditional is for backwards compatibility (backcompat); `0` will not be allowed in future.
6567
$this->lineNumber = $lineNumber !== 0 ? $lineNumber : null;
6668
$this->columnNumber = $columnNumber;
69+
70+
return $this;
6771
}
6872
}

src/Position/Positionable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public function getColNo(): int;
4040
* Providing zero for this parameter is deprecated in version 8.9.0, and will not be supported from v9.0.
4141
* Use `null` instead when no line number is available.
4242
* @param int<0, max>|null $columnNumber
43+
*
44+
* @return $this fluent interface
4345
*/
44-
public function setPosition(?int $lineNumber, ?int $columnNumber = null): void;
46+
public function setPosition(?int $lineNumber, ?int $columnNumber = null): Positionable;
4547
}

0 commit comments

Comments
 (0)