Completed
Push — master ( 7cf2a7...686a12 )
by Matthias
09:06
created

ControllerServiceFactory::createService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace MaglLegacyApplication\Factory;
5
6
7
use Interop\Container\ContainerInterface;
8
use Interop\Container\Exception\ContainerException;
9
use MaglLegacyApplication\Service\ControllerService;
10
use Zend\Mvc\MvcEvent;
11
use Zend\Mvc\Router\RouteMatch as ZF2RouteMatch;
12
use Zend\Router\RouteMatch;
13
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
14
use Zend\ServiceManager\Exception\ServiceNotFoundException;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface;
17
18
class ControllerServiceFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
19
{
20
21
    /**
22
     * Create service
23
     *
24
     * @param ServiceLocatorInterface $serviceLocator
25
     * @return mixed
26
     */
27
    public function createService(ServiceLocatorInterface $serviceLocator)
28
    {
29
        return $this->__invoke($serviceLocator, 'MaglControllerService');
30
    }
31
32
    /**
33
     * Create an object
34
     *
35
     * @param ContainerInterface $container
36
     * @param string $requestedName
37
     * @param null|array $options
38
     * @return object
39
     * @throws ServiceNotFoundException if unable to resolve the service.
40
     * @throws ServiceNotCreatedException if an exception is raised when
41
     *     creating a service.
42
     * @throws ContainerException if any other error occurs
43
     */
44
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
45
    {
46
        $eventManager = $container->get('Application')->getEventManager();
47
48
        $event = new MvcEvent();
49
        $event->setApplication($container->get('Application'));
50
        $event->setTarget($container->get('Application'));
51
        $event->setRequest($container->get('Request'));
52
        $event->setRouter($container->get('Router'));
53
54
        $routeMatch = null;
0 ignored issues
show
Unused Code introduced by
$routeMatch is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
        if(class_exists('\Zend\Mvc\Router\RouteMatch')) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
56
            // ZF2.5 compatibility
57
            $routeMatch = new ZF2RouteMatch(array());
58
        } else {
59
            $routeMatch = new RouteMatch(array());
60
        }
61
        $event->setRouteMatch($routeMatch);
62
63
        return new ControllerService($eventManager, $event);
64
    }
65
}
66