Skip to content

Commit a3ea98c

Browse files
committed
[CLEANUP] Make Commentable type annotations more specific
1 parent b561b72 commit a3ea98c

File tree

8 files changed

+27
-39
lines changed

8 files changed

+27
-39
lines changed

config/phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,6 @@ parameters:
126126
count: 2
127127
path: ../src/RuleSet/RuleSet.php
128128

129-
-
130-
message: '#^Parameter \#1 \$comments \(array\<string, Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\RuleSet\\RuleSet\:\:addComments\(\) should be contravariant with parameter \$comments \(array\<Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\Comment\\Commentable\:\:addComments\(\)$#'
131-
identifier: method.childParameterType
132-
count: 1
133-
path: ../src/RuleSet/RuleSet.php
134-
135-
-
136-
message: '#^Parameter \#1 \$comments \(array\<string, Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\RuleSet\\RuleSet\:\:setComments\(\) should be contravariant with parameter \$comments \(array\<Sabberworm\\CSS\\Comment\\Comment\>\) of method Sabberworm\\CSS\\Comment\\Commentable\:\:setComments\(\)$#'
137-
identifier: method.childParameterType
138-
count: 1
139-
path: ../src/RuleSet/RuleSet.php
140-
141129
-
142130
message: '#^Parameters should have "Sabberworm\\CSS\\Rule\\Rule" types as the only types passed to this method$#'
143131
identifier: typePerfect.narrowPublicClassMethodParamType

src/CSSList/CSSList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
abstract class CSSList implements Renderable, Commentable
3535
{
3636
/**
37-
* @var array<array-key, Comment>
37+
* @var list<Comment>
3838
*
3939
* @internal since 8.8.0
4040
*/
@@ -460,23 +460,23 @@ public function getContents()
460460
}
461461

462462
/**
463-
* @param array<array-key, Comment> $comments
463+
* @param array<int<0, max>, Comment> $comments
464464
*/
465465
public function addComments(array $comments): void
466466
{
467467
$this->comments = \array_merge($this->comments, $comments);
468468
}
469469

470470
/**
471-
* @return array<array-key, Comment>
471+
* @return list<Comment>
472472
*/
473473
public function getComments(): array
474474
{
475475
return $this->comments;
476476
}
477477

478478
/**
479-
* @param array<array-key, Comment> $comments
479+
* @param list<Comment> $comments
480480
*/
481481
public function setComments(array $comments): void
482482
{

src/Comment/Commentable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
interface Commentable
88
{
99
/**
10-
* @param array<array-key, Comment> $comments
10+
* @param array<int<0, max>, Comment> $comments
1111
*/
1212
public function addComments(array $comments): void;
1313

1414
/**
15-
* @return array<array-key, Comment>
15+
* @return list<Comment>
1616
*/
1717
public function getComments(): array;
1818

1919
/**
20-
* @param array<array-key, Comment> $comments
20+
* @param list<Comment> $comments
2121
*/
2222
public function setComments(array $comments): void;
2323
}

src/Property/CSSNamespace.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CSSNamespace implements AtRule
2828
private $lineNumber;
2929

3030
/**
31-
* @var array<array-key, Comment>
31+
* @var list<Comment>
3232
*
3333
* @internal since 8.8.0
3434
*/
@@ -121,23 +121,23 @@ public function atRuleArgs(): array
121121
}
122122

123123
/**
124-
* @param array<array-key, Comment> $comments
124+
* @param array<int<0, max>, Comment> $comments
125125
*/
126126
public function addComments(array $comments): void
127127
{
128128
$this->comments = \array_merge($this->comments, $comments);
129129
}
130130

131131
/**
132-
* @return array<array-key, Comment>
132+
* @return list<Comment>
133133
*/
134134
public function getComments(): array
135135
{
136136
return $this->comments;
137137
}
138138

139139
/**
140-
* @param array<array-key, Comment> $comments
140+
* @param list<Comment> $comments
141141
*/
142142
public function setComments(array $comments): void
143143
{

src/Property/Charset.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Charset implements AtRule
3131
protected $lineNumber;
3232

3333
/**
34-
* @var array<array-key, Comment>
34+
* @var list<Comment>
3535
*
3636
* @internal since 8.8.0
3737
*/
@@ -101,23 +101,23 @@ public function atRuleArgs()
101101
}
102102

103103
/**
104-
* @param array<array-key, Comment> $comments
104+
* @param array<int<0, max>, Comment> $comments
105105
*/
106106
public function addComments(array $comments): void
107107
{
108108
$this->comments = \array_merge($this->comments, $comments);
109109
}
110110

111111
/**
112-
* @return array<array-key, Comment>
112+
* @return list<Comment>
113113
*/
114114
public function getComments(): array
115115
{
116116
return $this->comments;
117117
}
118118

119119
/**
120-
* @param array<array-key, Comment> $comments
120+
* @param list<Comment> $comments
121121
*/
122122
public function setComments(array $comments): void
123123
{

src/Property/Import.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Import implements AtRule
3131
protected $lineNumber;
3232

3333
/**
34-
* @var array<array-key, Comment>
34+
* @var list<Comment>
3535
*
3636
* @internal since 8.8.0
3737
*/
@@ -107,23 +107,23 @@ public function atRuleArgs(): array
107107
}
108108

109109
/**
110-
* @param array<array-key, Comment> $comments
110+
* @param array<int<0, max>, Comment> $comments
111111
*/
112112
public function addComments(array $comments): void
113113
{
114114
$this->comments = \array_merge($this->comments, $comments);
115115
}
116116

117117
/**
118-
* @return array<array-key, Comment>
118+
* @return list<Comment>
119119
*/
120120
public function getComments(): array
121121
{
122122
return $this->comments;
123123
}
124124

125125
/**
126-
* @param array<array-key, Comment> $comments
126+
* @param list<Comment> $comments
127127
*/
128128
public function setComments(array $comments): void
129129
{

src/Rule/Rule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Rule implements Renderable, Commentable
4949
protected $columnNumber;
5050

5151
/**
52-
* @var array<array-key, Comment>
52+
* @var list<Comment>
5353
*
5454
* @internal since 8.8.0
5555
*/
@@ -249,23 +249,23 @@ public function render(OutputFormat $outputFormat): string
249249
}
250250

251251
/**
252-
* @param array<array-key, Comment> $comments
252+
* @param array<int<0, max>, Comment> $comments
253253
*/
254254
public function addComments(array $comments): void
255255
{
256256
$this->comments = \array_merge($this->comments, $comments);
257257
}
258258

259259
/**
260-
* @return array<array-key, Comment>
260+
* @return list<Comment>
261261
*/
262262
public function getComments(): array
263263
{
264264
return $this->comments;
265265
}
266266

267267
/**
268-
* @param array<array-key, Comment> $comments
268+
* @param list<Comment> $comments
269269
*/
270270
public function setComments(array $comments): void
271271
{

src/RuleSet/RuleSet.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ abstract class RuleSet implements Renderable, Commentable
4040
protected $lineNumber;
4141

4242
/**
43-
* @var array<array-key, Comment>
43+
* @var list<Comment>
4444
*
4545
* @internal since 8.8.0
4646
*/
@@ -301,23 +301,23 @@ protected function renderRules(OutputFormat $outputFormat): string
301301
}
302302

303303
/**
304-
* @param array<string, Comment> $comments
304+
* @param array<int<0, max>, Comment> $comments
305305
*/
306306
public function addComments(array $comments): void
307307
{
308308
$this->comments = \array_merge($this->comments, $comments);
309309
}
310310

311311
/**
312-
* @return array<string, Comment>
312+
* @return list<Comment>
313313
*/
314314
public function getComments(): array
315315
{
316316
return $this->comments;
317317
}
318318

319319
/**
320-
* @param array<string, Comment> $comments
320+
* @param list<Comment> $comments
321321
*/
322322
public function setComments(array $comments): void
323323
{

0 commit comments

Comments
 (0)