Completed
Push — refactor-entity-validators ( 9b4b77...c6627d )
by Stefano
13:07 queued 10:18
created

DataMapperManagerFactory::createService()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.5923

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 17
ccs 6
cts 9
cp 0.6667
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 4.5923
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 6
    public function createService(ServiceLocatorInterface $serviceLocator)
23
    {
24
        $config = $serviceLocator->get('Config');
25
26 6
        $dmmConfig = isset($config['thorr_persistence_dmm'])
27
            ? new DataMapperManagerConfig($config['thorr_persistence_dmm'])
28 6
            : null;
29
30
        $dataMapperManager = new DataMapperManager($dmmConfig);
31
        $dataMapperManager->setServiceLocator($serviceLocator);
32
33 5
        if (isset($config['di']) && $serviceLocator->has('Di')) {
34
            $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
        }
36
37 6
        return $dataMapperManager;
38 6
    }
39
}
40