Completed
Pull Request — develop (#683)
by Tom
01:23
created

StorageFactory::__invoke()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.7
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 3.009
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModule\Service\Authentication;
6
7
use DoctrineModule\Authentication\Storage\ObjectRepository;
8
use DoctrineModule\Options\Authentication;
9
use DoctrineModule\Service\AbstractFactory;
10
use Interop\Container\ContainerInterface;
11
use Laminas\ServiceManager\ServiceLocatorInterface;
12
use function assert;
13
use function is_string;
14
15
/**
16
 * Factory to create authentication storage object.
17
 *
18
 * @link    http://www.doctrine-project.org/
19
 */
20
class StorageFactory extends AbstractFactory
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25 3
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
26
    {
27 3
        $options = $this->getOptions($container, 'authentication');
28 3
        assert($options instanceof Authentication);
29
30 3
        $objectManager = $options->getObjectManager();
31 3
        if (is_string($objectManager)) {
32
            $options->setObjectManager($container->get($objectManager));
33
        }
34
35 3
        $storage = $options->getStorage();
36 3
        if (is_string($storage)) {
37 3
            $options->setStorage($container->get($storage));
38
        }
39
40 3
        return new ObjectRepository($options);
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     *
46
     * @return ObjectRepository
47
     */
48 2
    public function createService(ServiceLocatorInterface $container)
49
    {
50 2
        return $this($container, ObjectRepository::class);
51
    }
52
53 3
    public function getOptionsClass() : string
54
    {
55 3
        return 'DoctrineModule\Options\Authentication';
56
    }
57
}
58