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

IndexListSelector::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\ArrayViewInterface;
6
use Smoren\ArrayView\Interfaces\IndexListSelectorInterface;
7
use Smoren\ArrayView\Views\ArrayIndexListView;
8
9
final class IndexListSelector implements IndexListSelectorInterface
10
{
11
    /**
12
     * @var array<int>
13
     */
14
    private array $value;
15
16
    /**
17
     * @param array<int>|ArrayViewInterface<int> $value
18
     */
19
    public function __construct($value)
20
    {
21
        $this->value = \is_array($value) ? $value : $value->toArray();
0 ignored issues
show
Documentation Bug introduced by
is_array($value) ? $value : $value->toArray() is of type array<mixed,Smoren\ArrayView\Interfaces\T|mixed>, but the property $value was declared to be of type integer[]. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
22
    }
23
24
    /**
25
     * @template T
26
     *
27
     * @param ArrayViewInterface<T> $source
28
     * @param bool|null $readonly
29
     *
30
     * @return ArrayIndexListView<T>
31
     *
32
     * {@inheritDoc}
33
     */
34
    public function select(ArrayViewInterface $source, ?bool $readonly = null): ArrayIndexListView
35
    {
36
        return new ArrayIndexListView($source, $this->value, $readonly ?? $source->isReadonly());
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function getValue(): array
43
    {
44
        return $this->value;
45
    }
46
}
47