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

AdapterFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 33
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 2
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\Adapter\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 adapter object.
17
 *
18
 * @link    http://www.doctrine-project.org/
19
 */
20
class AdapterFactory extends AbstractFactory
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25 2
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
26
    {
27 2
        $options = $this->getOptions($container, 'authentication');
28 2
        assert($options instanceof Authentication);
29
30 2
        $objectManager = $options->getObjectManager();
31 2
        if (is_string($objectManager)) {
32
            $options->setObjectManager($container->get($objectManager));
33
        }
34
35 2
        return new ObjectRepository($options);
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     *
41
     * @return ObjectRepository
42
     */
43 1
    public function createService(ServiceLocatorInterface $serviceLocator)
44
    {
45 1
        return $this($serviceLocator, ObjectRepository::class);
46
    }
47
48 2
    public function getOptionsClass() : string
49
    {
50 2
        return 'DoctrineModule\Options\Authentication';
51
    }
52
}
53