From 6a0cfa1f57f3e3ee4b1d2fb237263aadefa08ef1 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Thu, 22 May 2025 02:02:22 +0100 Subject: [PATCH] [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. --- CHANGELOG.md | 2 ++ src/Position/Position.php | 6 +++++- src/Position/Positionable.php | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05c0f51d..e603df7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ Please also have a look at our ### Changed +- `setPosition()` (in `Rule` and other classes) now has fluent interface, + returning itself (#1259) - `RuleSet::removeRule()` now only allows `Rule` as the parameter (implementing classes are `AtRuleSet` and `DeclarationBlock`); use `removeMatchingRules()` or `removeAllRules()` for other functions (#1255) diff --git a/src/Position/Position.php b/src/Position/Position.php index 655f34b9..0771453b 100644 --- a/src/Position/Position.php +++ b/src/Position/Position.php @@ -58,11 +58,15 @@ public function getColNo(): int /** * @param int<0, max>|null $lineNumber * @param int<0, max>|null $columnNumber + * + * @return $this fluent interface */ - public function setPosition(?int $lineNumber, ?int $columnNumber = null): void + public function setPosition(?int $lineNumber, ?int $columnNumber = null): Positionable { // The conditional is for backwards compatibility (backcompat); `0` will not be allowed in future. $this->lineNumber = $lineNumber !== 0 ? $lineNumber : null; $this->columnNumber = $columnNumber; + + return $this; } } diff --git a/src/Position/Positionable.php b/src/Position/Positionable.php index 25a8295a..675fb55f 100644 --- a/src/Position/Positionable.php +++ b/src/Position/Positionable.php @@ -40,6 +40,8 @@ public function getColNo(): int; * Providing zero for this parameter is deprecated in version 8.9.0, and will not be supported from v9.0. * Use `null` instead when no line number is available. * @param int<0, max>|null $columnNumber + * + * @return $this fluent interface */ - public function setPosition(?int $lineNumber, ?int $columnNumber = null): void; + public function setPosition(?int $lineNumber, ?int $columnNumber = null): Positionable; }