Completed
Push — master ( bd4c23...b341c0 )
by Filipe
10:29
created

ControllerDispatchInflectorSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 31.75 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 20
loc 63
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A its_a_controller_class_inflector() 0 4 1
A it_inflects_controller_dispatch_form_route_attributes() 0 11 1
A it_converts_dashed_url_controller_param_into_controller_class_names() 10 10 1
A it_converts_underscored_url_controller_param_into_controller_class_names() 10 10 1
A getMatchers() 0 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace spec\Slick\Mvc\Http\Dispatcher;
4
5
use Aura\Router\Route;
6
use PhpSpec\Exception\Example\FailureException;
7
use PhpSpec\Wrapper\Subject;
8
use Slick\Mvc\Http\Dispatcher\ControllerDispatch;
9
use Slick\Mvc\Http\Dispatcher\ControllerDispatchInflector;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
use Slick\Mvc\Http\Dispatcher\ControllerDispatchInflectorInterface;
13
14
class ControllerDispatchInflectorSpec extends ObjectBehavior
15
{
16
    function it_is_initializable()
17
    {
18
        $this->shouldHaveType(ControllerDispatchInflector::class);
19
    }
20
21
    function its_a_controller_class_inflector()
22
    {
23
        $this->shouldBeAnInstanceOf(ControllerDispatchInflectorInterface::class);
24
    }
25
26
    function it_inflects_controller_dispatch_form_route_attributes()
27
    {
28
        $route = new Route();
29
        $route->attributes([
30
            'namespace' => 'Controller',
31
            'controller' => 'pages',
32
            'action' => 'index',
33
            'args' => [123, 'test']
34
        ]);
35
        $this->inflect($route)->shouldBeAnInstanceOf(ControllerDispatch::class);
36
    }
37
38 View Code Duplication
    function it_converts_dashed_url_controller_param_into_controller_class_names()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $route = new Route();
41
        $route->attributes([
42
            'namespace' => 'Controller',
43
            'controller' => 'yellow-pages',
44
            'action' => 'index'
45
        ]);
46
        $this->inflect($route)->shouldHaveControllerNamed('Controller\YellowPages');
47
    }
48
49 View Code Duplication
    function it_converts_underscored_url_controller_param_into_controller_class_names()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $route = new Route();
52
        $route->attributes([
53
            'namespace' => 'Controller',
54
            'controller' => 'yellow_pages',
55
            'action' => 'index'
56
        ]);
57
        $this->inflect($route)->shouldHaveControllerNamed('Controller\YellowPages');
58
    }
59
60
61
    public function getMatchers()
62
    {
63
        return [
64
            'haveControllerNamed' => function (ControllerDispatch $subject, $name) {
65
66
                if ($subject->getControllerClassName() !== $name) {
67
                    throw new FailureException(
68
                        "Expected controller name to be '{$name}', ".
69
                        "but got {$subject->getControllerClassName()}"
70
                    );
71
                }
72
                return true;
73
            }
74
        ];
75
    }
76
}
77