DoctrineObjectHydratorLocatorFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 16 2
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\Hydrator;
7
8
use Nnx\Doctrine\ObjectManager\ObjectManagerAutoDetectorInterface;
9
use Zend\ServiceManager\AbstractPluginManager;
10
use Zend\ServiceManager\FactoryInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
use Nnx\Doctrine\ObjectManager\DoctrineObjectManagerInterface;
13
14
/**
15
 * Class DoctrineObjectHydratorLocatorFactory
16
 *
17
 * @package Nnx\Doctrine\Hydrator
18
 */
19
class DoctrineObjectHydratorLocatorFactory implements FactoryInterface
20
{
21
    /**
22
     * @param ServiceLocatorInterface $serviceLocator
23
     *
24
     * @return DoctrineObjectHydratorLocator
25
     *
26
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
27
     */
28
    public function createService(ServiceLocatorInterface $serviceLocator)
29
    {
30
        $appServiceLocator = $serviceLocator;
31
        if ($appServiceLocator instanceof AbstractPluginManager) {
32
            $appServiceLocator->getServiceLocator();
0 ignored issues
show
Unused Code introduced by
The call to the method Zend\ServiceManager\Abst...er::getServiceLocator() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
33
        }
34
35
        /** @var ObjectManagerAutoDetectorInterface $objectManagerAutoDetector */
36
        $objectManagerAutoDetector = $appServiceLocator->get(ObjectManagerAutoDetectorInterface::class);
37
38
        /** @var DoctrineObjectManagerInterface $objectManager */
39
        $objectManager = $appServiceLocator->get(DoctrineObjectManagerInterface::class);
40
41
42
        return new DoctrineObjectHydratorLocator($objectManagerAutoDetector, $objectManager);
43
    }
44
}
45