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

StorageFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 38
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 3
A createService() 0 4 1
A getOptionsClass() 0 4 1
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