Skip to content

Commit c5d968c

Browse files
committed
[CLEANUP] Make Commentable type annotations more specific
1 parent 4889353 commit c5d968c

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
@@ -108,18 +108,6 @@ parameters:
108108
count: 2
109109
path: ../src/RuleSet/RuleSet.php
110110

111-
-
112-
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\(\)$#'
113-
identifier: method.childParameterType
114-
count: 1
115-
path: ../src/RuleSet/RuleSet.php
116-
117-
-
118-
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\(\)$#'
119-
identifier: method.childParameterType
120-
count: 1
121-
path: ../src/RuleSet/RuleSet.php
122-
123111
-
124112
message: '#^Parameters should have "Sabberworm\\CSS\\Rule\\Rule" types as the only types passed to this method$#'
125113
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
*/
@@ -101,23 +101,23 @@ public function atRuleArgs(): array
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/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
*/
@@ -305,23 +305,23 @@ protected function renderRules(OutputFormat $outputFormat): string
305305
}
306306

307307
/**
308-
* @param array<string, Comment> $comments
308+
* @param array<int<0, max>, Comment> $comments
309309
*/
310310
public function addComments(array $comments): void
311311
{
312312
$this->comments = \array_merge($this->comments, $comments);
313313
}
314314

315315
/**
316-
* @return array<string, Comment>
316+
* @return list<Comment>
317317
*/
318318
public function getComments(): array
319319
{
320320
return $this->comments;
321321
}
322322

323323
/**
324-
* @param array<string, Comment> $comments
324+
* @param list<Comment> $comments
325325
*/
326326
public function setComments(array $comments): void
327327
{

0 commit comments

Comments
 (0)