Padding::padLeft()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
The expression return $this->newCopy(ar...ms(), $amount, $value)) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Padding.
Loading history...
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
Bug Best Practice introduced by
The expression return $this->newCopy(ar...s(), -$amount, $value)) returns the type Stratadox\Collection\Collection which is incompatible with the documented return type Stratadox\ImmutableCollection\Padding.
Loading history...
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