Completed
Push — master ( 167a70...cb59b7 )
by Abdul Malik
9s
created

SessionToolbarControllerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license.
18
 */
19
namespace SanSessionToolbar\Factory\Controller;
20
21
use Interop\Container\ContainerInterface;
22
use SanSessionToolbar\Controller\SessionToolbarController;
23
use Zend\ServiceManager\FactoryInterface;
24
use Zend\ServiceManager\ServiceLocatorAwareInterface;
25
use Zend\ServiceManager\ServiceLocatorInterface;
26
27
/**
28
 * Factory class for SessionToolbarController creation.
29
 *
30
 * @author Abdul Malik Ikhsan <[email protected]>
31
 */
32
class SessionToolbarControllerFactory implements FactoryInterface
33
{
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function createService(ServiceLocatorInterface $serviceLocator)
38
    {
39
        $services = $this->getParentServiceLocator($serviceLocator);
40
41
        return new SessionToolbarController(
42
            (object) $services->get('ViewRenderer'),
43
            (object) $services->get('SanSessionManager')
44
        );
45
    }
46
47
    /**
48
     * Get Parent ServiceLocator.
49
     *
50
     * @param ServiceLocatorInterface
51
     *
52
     * @return ServiceLocatorInterface
53
     */
54
    private function getParentServiceLocator(ServiceLocatorInterface $serviceLocator)
55
    {
56
        if ($serviceLocator instanceof ServiceLocatorAwareInterface) {
57
            return $serviceLocator->getServiceLocator();
58
        }
59
60
        return $serviceLocator;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function __invoke(ContainerInterface $serviceLocator, $requestedName, array $options = null)
0 ignored issues
show
Unused Code introduced by
The parameter $requestedName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        return $this->createService($serviceLocator);
0 ignored issues
show
Compatibility introduced by
$serviceLocator of type object<Interop\Container\ContainerInterface> is not a sub-type of object<Zend\ServiceManag...erviceLocatorInterface>. It seems like you assume a child interface of the interface Interop\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
69
    }
70
}
71