Skip to content

Commit 4e00c05

Browse files
committed
[TASK] Add native type declarations for CSSList
Part of #811
1 parent f9609c4 commit 4e00c05

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Please also have a look at our
3434
- Use more native type declarations and strict mode
3535
(#641, #772, #774, #778, #804, #841, #873, #875, #891, #922, #923, #933, #958,
3636
#964, #967, #1000, #1044, #1134, #1136, #1137, #1139, #1140, #1141, #1145,
37-
#1162, #1163, #1166, #1172, #1174, #1178, #1179)
37+
#1162, #1163, #1166, #1172, #1174, #1178, #1179, #1181)
3838
- Add visibility to all class/interface constants (#469)
3939

4040
### Deprecated

src/CSSList/CSSList.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract class CSSList implements Renderable, Commentable
4141
protected $comments = [];
4242

4343
/**
44-
* @var array<int, RuleSet|CSSList|Import|Charset>
44+
* @var array<int<0, max>, RuleSet|CSSList|Import|Charset>
4545
*
4646
* @internal since 8.8.0
4747
*/
@@ -283,11 +283,9 @@ public function append($item): void
283283
/**
284284
* Splices the list of contents.
285285
*
286-
* @param int $offset
287-
* @param int $length
288286
* @param array<int, RuleSet|CSSList|Import|Charset> $replacement
289287
*/
290-
public function splice($offset, $length = null, $replacement = null): void
288+
public function splice(int $offset, ?int $length = null, ?array $replacement = null): void
291289
{
292290
\array_splice($this->contents, $offset, $length, $replacement);
293291
}
@@ -317,13 +315,14 @@ public function insertBefore($item, $sibling): void
317315
*
318316
* @return bool whether the item was removed
319317
*/
320-
public function remove($itemToRemove)
318+
public function remove($itemToRemove): bool
321319
{
322320
$key = \array_search($itemToRemove, $this->contents, true);
323321
if ($key !== false) {
324322
unset($this->contents[$key]);
325323
return true;
326324
}
325+
327326
return false;
328327
}
329328

@@ -333,10 +332,9 @@ public function remove($itemToRemove)
333332
* @param RuleSet|Import|Charset|CSSList $oldItem
334333
* May be a `RuleSet` (most likely a `DeclarationBlock`), an `Import`, a `Charset`
335334
* or another `CSSList` (most likely a `MediaQuery`)
336-
*
337-
* @return bool
335+
* @param RuleSet|Import|Charset|CSSList|array<RuleSet|Import|Charset|CSSList> $newItem
338336
*/
339-
public function replace($oldItem, $newItem)
337+
public function replace($oldItem, $newItem): bool
340338
{
341339
$key = \array_search($oldItem, $this->contents, true);
342340
if ($key !== false) {
@@ -347,6 +345,7 @@ public function replace($oldItem, $newItem)
347345
}
348346
return true;
349347
}
348+
350349
return false;
351350
}
352351

@@ -364,10 +363,10 @@ public function setContents(array $contents): void
364363
/**
365364
* Removes a declaration block from the CSS list if it matches all given selectors.
366365
*
367-
* @param DeclarationBlock|array<array-key, Selector>|string $selectors the selectors to match
366+
* @param DeclarationBlock|array<Selector>|string $selectors the selectors to match
368367
* @param bool $removeAll whether to stop at the first declaration block found or remove all blocks
369368
*/
370-
public function removeDeclarationBlockBySelector($selectors, $removeAll = false): void
369+
public function removeDeclarationBlockBySelector($selectors, bool $removeAll = false): void
371370
{
372371
if ($selectors instanceof DeclarationBlock) {
373372
$selectors = $selectors->getSelectors();
@@ -444,17 +443,15 @@ protected function renderListContents(OutputFormat $outputFormat): string
444443

445444
/**
446445
* Return true if the list can not be further outdented. Only important when rendering.
447-
*
448-
* @return bool
449446
*/
450-
abstract public function isRootList();
447+
abstract public function isRootList(): bool;
451448

452449
/**
453450
* Returns the stored items.
454451
*
455-
* @return array<int, RuleSet|Import|Charset|CSSList>
452+
* @return array<int<0, max>, RuleSet|Import|Charset|CSSList>
456453
*/
457-
public function getContents()
454+
public function getContents(): array
458455
{
459456
return $this->contents;
460457
}

0 commit comments

Comments
 (0)