DataMapperManagerFactory::createService()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
ccs 11
cts 11
cp 1
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 4
1
<?php
2
/**
3
 * @author Stefano Torresi (http://stefanotorresi.it)
4
 * @license See the file LICENSE.txt for copying permission.
5
 * ************************************************
6
 */
7
8
namespace Thorr\Persistence\DataMapper\Manager;
9
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
class DataMapperManagerFactory implements FactoryInterface
14
{
15
    /**
16
     * Create service
17
     *
18
     * @param ServiceLocatorInterface $serviceLocator
19
     *
20
     * @return DataMapperManager
21
     */
22 7
    public function createService(ServiceLocatorInterface $serviceLocator)
23
    {
24 7
        $config = $serviceLocator->get('Config');
25
26 7
        $dmmConfig = isset($config['thorr_persistence_dmm'])
27 7
            ? new DataMapperManagerConfig($config['thorr_persistence_dmm'])
28 7
            : null;
29
30 7
        $dataMapperManager = new DataMapperManager($dmmConfig);
31 7
        $dataMapperManager->setServiceLocator($serviceLocator);
32
33 7
        if (isset($config['di']) && $serviceLocator->has('Di')) {
34 1
            $dataMapperManager->addAbstractFactory($serviceLocator->get('DiAbstractServiceFactory'));
0 ignored issues
show
Documentation introduced by
$serviceLocator->get('DiAbstractServiceFactory') is of type object|array, but the function expects a object<Zend\ServiceManag...actoryInterface>|string.

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...
35 1
        }
36
37 7
        return $dataMapperManager;
38
    }
39
}
40