Skip to content

Commit f9685bb

Browse files
authored
[TASK] Set line number to null by default (#1288)
No longer allow or support `0` as a default line or column number. Part of #974
1 parent 710dab9 commit f9685bb

25 files changed

+47
-61
lines changed

CHANGELOG.md

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

3333
### Changed
3434

35+
- The default line (and column) number is now `null` (not zero) (#1288)
3536
- `setPosition()` (in `Rule` and other classes) now has fluent interface,
3637
returning itself (#1259)
3738
- `RuleSet::removeRule()` now only allows `Rule` as the parameter

src/CSSList/AtRuleBlockList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class AtRuleBlockList extends CSSBlockList implements AtRule
2424

2525
/**
2626
* @param non-empty-string $type
27-
* @param int<0, max> $lineNumber
27+
* @param int<1, max>|null $lineNumber
2828
*/
29-
public function __construct(string $type, string $arguments = '', int $lineNumber = 0)
29+
public function __construct(string $type, string $arguments = '', ?int $lineNumber = null)
3030
{
3131
parent::__construct($lineNumber);
3232
$this->type = $type;

src/CSSList/CSSList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ abstract class CSSList implements CSSElement, CSSListItem, Positionable
4848
protected $contents = [];
4949

5050
/**
51-
* @param int<0, max> $lineNumber
51+
* @param int<1, max>|null $lineNumber
5252
*/
53-
public function __construct(int $lineNumber = 0)
53+
public function __construct(?int $lineNumber = null)
5454
{
5555
$this->setPosition($lineNumber);
5656
}

src/Comment/Comment.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class Comment implements Positionable, Renderable
2121
protected $commentText;
2222

2323
/**
24-
* @param int<0, max> $lineNumber
24+
* @param int<1, max>|null $lineNumber
2525
*/
26-
public function __construct(string $commentText = '', int $lineNumber = 0)
26+
public function __construct(string $commentText = '', ?int $lineNumber = null)
2727
{
2828
$this->commentText = $commentText;
2929
$this->setPosition($lineNumber);

src/Parsing/SourceException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ class SourceException extends \Exception implements Positionable
1212
use Position;
1313

1414
/**
15-
* @param int<0, max> $lineNumber
15+
* @param int<1, max>|null $lineNumber
1616
*/
17-
public function __construct(string $message, int $lineNumber = 0)
17+
public function __construct(string $message, ?int $lineNumber = null)
1818
{
1919
$this->setPosition($lineNumber);
2020
if ($lineNumber !== 0) {

src/Parsing/UnexpectedTokenException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class UnexpectedTokenException extends SourceException
1111
{
1212
/**
1313
* @param 'literal'|'identifier'|'count'|'expression'|'search'|'custom' $matchType
14-
* @param int<0, max> $lineNumber
14+
* @param int<1, max>|null $lineNumber
1515
*/
16-
public function __construct(string $expected, string $found, string $matchType = 'literal', int $lineNumber = 0)
16+
public function __construct(string $expected, string $found, string $matchType = 'literal', ?int $lineNumber = null)
1717
{
1818
$message = "Token “{$expected}” ({$matchType}) not found. Got “{$found}”.";
1919
if ($matchType === 'search') {

src/Position/Position.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ public function getColumnNumber(): ?int
4848
}
4949

5050
/**
51-
* @param int<0, max>|null $lineNumber
51+
* @param int<1, max>|null $lineNumber
5252
* @param int<0, max>|null $columnNumber
5353
*
5454
* @return $this fluent interface
5555
*/
5656
public function setPosition(?int $lineNumber, ?int $columnNumber = null): Positionable
5757
{
58-
// The conditional is for backwards compatibility (backcompat); `0` will not be allowed in future.
59-
$this->lineNumber = $lineNumber !== 0 ? $lineNumber : null;
58+
$this->lineNumber = $lineNumber;
6059
$this->columnNumber = $columnNumber;
6160

6261
return $this;

src/Position/Positionable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public function getLineNo(): int;
2929
public function getColumnNumber(): ?int;
3030

3131
/**
32-
* @param int<0, max>|null $lineNumber
33-
* Providing zero for this parameter is deprecated in version 8.9.0, and will not be supported from v9.0.
34-
* Use `null` instead when no line number is available.
32+
* @param int<1, max>|null $lineNumber
3533
* @param int<0, max>|null $columnNumber
3634
*
3735
* @return $this fluent interface

src/Property/CSSNamespace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class CSSNamespace implements AtRule, Positionable
3131

3232
/**
3333
* @param CSSString|URL $url
34-
* @param int<0, max> $lineNumber
34+
* @param int<1, max>|null $lineNumber
3535
*/
36-
public function __construct($url, ?string $prefix = null, int $lineNumber = 0)
36+
public function __construct($url, ?string $prefix = null, ?int $lineNumber = null)
3737
{
3838
$this->url = $url;
3939
$this->prefix = $prefix;

src/Property/Charset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ class Charset implements AtRule, Positionable
2929
private $charset;
3030

3131
/**
32-
* @param int<0, max> $lineNumber
32+
* @param int<1, max>|null $lineNumber
3333
*/
34-
public function __construct(CSSString $charset, int $lineNumber = 0)
34+
public function __construct(CSSString $charset, ?int $lineNumber = null)
3535
{
3636
$this->charset = $charset;
3737
$this->setPosition($lineNumber);

0 commit comments

Comments
 (0)