CollectionFactory::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\AuthClient\Factory;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Yii\AuthClient\Collection;
9
10
class CollectionFactory
11
{
12
    private array $clients;
13
14
    public function __construct(array $clients = [])
15
    {
16
        $this->clients = $clients;
17
    }
18
19
    public function __invoke(ContainerInterface $container): Collection
20
    {
21
        $clients = [];
22
        foreach ($this->clients as $name => $client) {
23
            if (!is_string($name)) {
24
                throw new \InvalidArgumentException('Client name must be set.');
25
            }
26
            $clients[$name] = $container->get($client);
27
        }
28
        return new Collection($clients);
29
    }
30
}
31