Passed
Push — master ( 0ec165...088218 )
by Smoren
02:34 queued 49s
created

SliceSelector::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Smoren\ArrayView\Selectors;
4
5
use Smoren\ArrayView\Interfaces\ArraySelectorInterface;
6
use Smoren\ArrayView\Interfaces\ArrayViewInterface;
7
use Smoren\ArrayView\Structs\Slice;
8
use Smoren\ArrayView\Views\ArraySliceView;
9
10
class SliceSelector extends Slice implements ArraySelectorInterface
11
{
12
    /**
13
     * @param Slice|string $slice
14
     */
15
    public function __construct($slice)
16
    {
17
        $s = Slice::toSlice($slice);
18
        parent::__construct($s->start, $s->end, $s->step);
19
    }
20
21
    /**
22
     * @template T
23
     *
24
     * @param ArrayViewInterface<T> $source
25
     * @param bool|null $readonly
26
     *
27
     * @return ArraySliceView<T>
28
     *
29
     * {@inheritDoc}
30
     */
31
    public function select(ArrayViewInterface $source, ?bool $readonly = null): ArrayViewInterface
32
    {
33
        return new ArraySliceView($source, $this, $readonly ?? $source->isReadonly());
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function getValue(): Slice
40
    {
41
        return $this;
42
    }
43
}
44