Completed
Pull Request — master (#165)
by Paul
03:21
created

RouterRequestContextFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createService() 0 7 1
A getConfigurationDefaults() 0 13 1
A processConfiguration() 0 9 2
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright   Copyright (c) 2011-2016 Paul Dragoonis <[email protected]>
6
 * @license     http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link        http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\ServiceManager\Factory;
12
13
use Symfony\Component\Routing\RequestContext;
14
use Zend\ServiceManager\ServiceLocatorInterface;
15
16
/**
17
 * RouterRequestContext Factory.
18
 *
19
 * @author     Vítor Brandão <[email protected]>
20
 */
21
class RouterRequestContextFactory extends AbstractFactory
22
{
23
    /**
24
     * Create and return the router.
25
     *
26
     * @param ServiceLocatorInterface $serviceLocator
27
     *
28
     * @return \PPI\Framework\Router\RouterListener
29
     */
30
    public function createService(ServiceLocatorInterface $serviceLocator)
31
    {
32
        $context = new RequestContext();
33
        $context->fromRequest($serviceLocator->get('Request'));
0 ignored issues
show
Documentation introduced by
$serviceLocator->get('Request') is of type object|array, but the function expects a object<Symfony\Component\HttpFoundation\Request>.

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...
34
35
        return $context;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41
    public function getConfigurationDefaults()
42
    {
43
        return array('framework' => array(
44
            'router' => array(
45
                // request_context
46
                'host'          => 'localhost',
47
                'scheme'        => 'http',
48
                // request_listener
49
                'http_port'     => '80',
50
                'https_port'    => '443',
51
            ),
52
        ));
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    protected function processConfiguration(array $config, ServiceLocatorInterface $serviceLocator = null)
59
    {
60
        $defaults = $this->getConfigurationDefaults();
61
        $defaults = $defaults['framework']['router'];
62
63
        return isset($config['framework']['router']) ?
64
            $this->mergeConfiguration($defaults, $config['framework']['router']) :
65
            $defaults;
66
    }
67
}
68