Skip to content

[TASK] Have setPosition() implement fluent interface #1259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/Position/Position.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion src/Position/Positionable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}