1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Stratadox\ImmutableCollection; |
||
6 | |||
7 | use function array_pad; |
||
8 | use Stratadox\Collection\Collection; |
||
9 | use Stratadox\Collection\Paddable; |
||
10 | |||
11 | /** |
||
12 | * Behaviour to pad the collection to match a certain size. |
||
13 | * |
||
14 | * Provides access to padding behaviour in the form of two methods that pad the |
||
15 | * collection on either the left or the right side. |
||
16 | * |
||
17 | * @package Stratadox\Collection |
||
18 | * @author Stratadox |
||
19 | */ |
||
20 | trait Padding |
||
21 | { |
||
22 | /** |
||
23 | * @see Paddable::padRight() |
||
24 | * @param int $amount |
||
25 | * @param mixed $value |
||
26 | * @return static |
||
27 | */ |
||
28 | public function padRight(int $amount, $value) |
||
29 | { |
||
30 | return $this->newCopy(array_pad($this->items(), $amount, $value)); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @see Paddable::padLeft() |
||
35 | * @param int $amount |
||
36 | * @param mixed $value |
||
37 | * @return static |
||
38 | */ |
||
39 | public function padLeft(int $amount, $value) |
||
40 | { |
||
41 | return $this->newCopy(array_pad($this->items(), -$amount, $value)); |
||
0 ignored issues
–
show
|
|||
42 | } |
||
43 | |||
44 | /** @see Collection::items() */ |
||
45 | abstract public function items(): array; |
||
46 | |||
47 | /** |
||
48 | * @see ImmutableCollection::newCopy() |
||
49 | * @param array $items |
||
50 | * @return Collection|static |
||
51 | */ |
||
52 | abstract protected function newCopy(array $items): Collection; |
||
53 | } |
||
54 |