AdapterFactory   A
last analyzed

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\Service\AbstractFactory;
9
use Interop\Container\ContainerInterface;
10
use Laminas\ServiceManager\ServiceLocatorInterface;
11
use function is_string;
12
13
/**
14
 * Factory to create authentication adapter object.
15
 *
16
 * @link    http://www.doctrine-project.org/
17
 */
18
class AdapterFactory extends AbstractFactory
19
{
20
    /**
21
     * {@inheritDoc}
22
     */
23 2
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
24
    {
25 2
        $options = $this->getOptions($container, 'authentication');
26
27 2
        $objectManager = $options->getObjectManager();
28 2
        if (is_string($objectManager)) {
29
            $options->setObjectManager($container->get($objectManager));
30
        }
31
32 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...
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     *
38
     * @return ObjectRepository
39
     */
40 1
    public function createService(ServiceLocatorInterface $serviceLocator)
41
    {
42 1
        return $this($serviceLocator, ObjectRepository::class);
43
    }
44
45 2
    public function getOptionsClass() : string
46
    {
47 2
        return 'DoctrineModule\Options\Authentication';
48
    }
49
}
50