Skip to content

Commit 23a106a

Browse files
committed
[TASK] Remove getLineNo()
Also no longer allow zero to be passed as line number to `setPosition()`. Closes #974.
1 parent 710dab9 commit 23a106a

37 files changed

+48
-383
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ Please also have a look at our
8080

8181
### Removed
8282

83+
- Remove `getLineNo()` from these classes (use `getLineNumber()` instead):
84+
`Comment`, `CSSList`, `SourceException`, `Charset`, `CSSNamespace`, `Import`,
85+
`Rule`, `DeclarationBlock`, `RuleSet`, `CSSFunction`, `Value` (#1258)
8386
- Remove `Rule::getColNo()` (use `getColumnNumber()` instead) (#1287)
8487
- Passing a string as the first argument to `getAllValues()` is no longer
8588
supported and will not work;

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: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ public function getLineNumber(): ?int
3131
return $this->lineNumber;
3232
}
3333

34-
/**
35-
* @return int<0, max>
36-
*/
37-
public function getLineNo(): int
38-
{
39-
return $this->getLineNumber() ?? 0;
40-
}
41-
4234
/**
4335
* @return int<0, max>|null
4436
*/
@@ -55,8 +47,7 @@ public function getColumnNumber(): ?int
5547
*/
5648
public function setPosition(?int $lineNumber, ?int $columnNumber = null): Positionable
5749
{
58-
// The conditional is for backwards compatibility (backcompat); `0` will not be allowed in future.
59-
$this->lineNumber = $lineNumber !== 0 ? $lineNumber : null;
50+
$this->lineNumber = $lineNumber;
6051
$this->columnNumber = $columnNumber;
6152

6253
return $this;

src/Position/Positionable.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,13 @@ interface Positionable
1616
*/
1717
public function getLineNumber(): ?int;
1818

19-
/**
20-
* @return int<0, max>
21-
*
22-
* @deprecated in version 8.9.0, will be removed in v9.0. Use `getLineNumber()` instead.
23-
*/
24-
public function getLineNo(): int;
25-
2619
/**
2720
* @return int<0, max>|null
2821
*/
2922
public function getColumnNumber(): ?int;
3023

3124
/**
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.
25+
* @param int<1, max>|null $lineNumber
3526
* @param int<0, max>|null $columnNumber
3627
*
3728
* @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)