RequestMatcherPlugin   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
cbo 4
dl 0
loc 55
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A loadServices() 0 12 1
A load() 0 4 1
1
<?php
2
namespace Fwk\Core\Plugins;
3
4
use Fwk\Core\Application;
5
use Fwk\Core\Components\RequestMatcher\RequestMatcherListener;
6
use Fwk\Core\Plugin;
7
use Fwk\Di\ClassDefinition;
8
use Fwk\Di\Container;
9
10
class RequestMatcherPlugin implements Plugin
11
{
12
    const SERVICE_NAME = 'requestMatcher';
13
14
    /**
15
     * Regex used to determine Action name
16
     *
17
     * @var null|string
18
     */
19
    private $actionRegex;
20
21
    /**
22
     * Constructor
23
     *
24
     * @param string|null $actionRegex Regex used to determine Action name
25
     *
26
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
     */
28
    function __construct($actionRegex = null)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
29
    {
30
        $this->actionRegex = $actionRegex;
31
    }
32
33
    /**
34
     * Apply Plugin's services to the existing Container
35
     *
36
     * @param Container $container App's Services Container
37
     *
38
     * @return void
39
     */
40
    public function loadServices(Container $container)
41
    {
42
        $container->set(
43
            self::SERVICE_NAME,
44
            new ClassDefinition('\Fwk\Core\Components\RequestMatcher\RequestMatcher',
45
                array(
46
                    $this->actionRegex
47
                )
48
            ),
49
            true
50
        );
51
    }
52
53
    /**
54
     * Returns a list of Actions for this plugin
55
     *
56
     * @param Application $app The running Application
57
     *
58
     * @return void
59
     */
60
    public function load(Application $app)
61
    {
62
        $app->addListener(new RequestMatcherListener(self::SERVICE_NAME));
63
    }
64
}