Completed
Push — master ( f2b8b4...a21374 )
by Tom
24s queued 11s
created

AdapterFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 32
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 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 is_string;
13
14
/**
15
 * Factory to create authentication adapter object.
16
 *
17
 * @link    http://www.doctrine-project.org/
18
 */
19
class AdapterFactory extends AbstractFactory
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24 2
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
25
    {
26 2
        $options = $this->getOptions($container, 'authentication');
27
28 2
        $objectManager = $options->getObjectManager();
29 2
        if (is_string($objectManager)) {
30
            $options->setObjectManager($container->get($objectManager));
31
        }
32
33 2
        return new ObjectRepository($options);
0 ignored issues
show
Documentation introduced by
$options is of type object<Laminas\Stdlib\AbstractOptions>, but the function expects a array<integer,*>|object<...Options\Authentication>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     *
39
     * @return ObjectRepository
40
     */
41 1
    public function createService(ServiceLocatorInterface $serviceLocator)
42
    {
43 1
        return $this($serviceLocator, ObjectRepository::class);
44
    }
45
46 2
    public function getOptionsClass() : string
47
    {
48 2
        return 'DoctrineModule\Options\Authentication';
49
    }
50
}
51