Passed
Push — master ( 13aaf0...8c7f52 )
by Ion
08:50
created

AdapterProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\ObjectStorage;
6
7
class AdapterProvider
8
{
9
    /** @var ObjectStorageAdapter[] */
10
    private iterable $adapters;
11
    private string $defaultAdapter;
12
13
    /**
14
     * @param ObjectStorageAdapter[] $adapters
15
     */
16 6
    public function __construct(iterable $adapters, string $defaultAdapter)
17
    {
18 6
        $this->adapters = $adapters;
0 ignored issues
show
Documentation Bug introduced by
It seems like $adapters of type iterable is incompatible with the declared type App\Infrastructure\Objec...\ObjectStorageAdapter[] of property $adapters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
19 6
        $this->defaultAdapter = $defaultAdapter;
20 6
    }
21
22 6
    public function __invoke(?string $name = null): ObjectStorageAdapter
23
    {
24 6
        $name ??= $this->defaultAdapter;
25 6
        $adapters = iterator_to_array($this->adapters);
26
27 6
        if (!\array_key_exists($name, $adapters)) {
28 1
            throw new \UnexpectedValueException(sprintf('Invalid adapter name "%s" provided. Available options are: %s', $name, implode(', ', array_keys($adapters))));
29
        }
30
31 6
        return $adapters[$name];
32
    }
33
}
34