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

AdapterProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 10 2
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