Passed
Pull Request — master (#81)
by
unknown
04:38 queued 01:05
created

RequestRefreshTokenSpec   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 105
Duplicated Lines 67.62 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 11
c 3
b 1
f 0
lcom 0
cbo 5
dl 71
loc 105
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_gets_from_query_param() 0 7 1
A it_gets_from_body() 0 7 1
A it_gets_from_json() 7 7 1
A it_gets_from_json_x() 7 7 1
A it_gets_from_json_parameter() 7 7 1
A it_gets_from_query_param_using_camel_case_naming() 10 10 1
A it_gets_from_body_using_camel_case_naming() 10 10 1
A it_gets_from_json_using_camel_case_naming() 10 10 1
A it_gets_from_json_x_using_camel_case_naming() 10 10 1
A it_gets_from_json_parameter_using_camel_case_naming() 10 10 1

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\Gesdinet\JWTRefreshTokenBundle\Request;
4
5
use Gesdinet\JWTRefreshTokenBundle\NameGenerator\NameGeneratorInterface;
6
use PhpSpec\ObjectBehavior;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class RequestRefreshTokenSpec extends ObjectBehavior
10
{
11
    public function let(NameGeneratorInterface $nameGenerator)
12
    {
13
        $this->beConstructedWith($nameGenerator);
14
15
        $nameGenerator->generateName('refresh_token')
16
            ->willReturn('refresh_token');
17
    }
18
19
    public function it_gets_from_query_param()
20
    {
21
        $request = Request::createFromGlobals();
22
        $request->attributes->set('refresh_token', 'abcd');
23
24
        $this->getRefreshToken($request)->shouldBe('abcd');
25
    }
26
27
    public function it_gets_from_body()
28
    {
29
        $request = Request::createFromGlobals();
30
        $request->request->set('refresh_token', 'abcd');
31
32
        $this->getRefreshToken($request)->shouldBe('abcd');
33
    }
34
35 View Code Duplication
    public function it_gets_from_json()
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...
36
    {
37
        $request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refresh_token' => 'abcd')));
38
        $request->headers->set('content_type', 'application/json');
39
40
        $this->getRefreshToken($request)->shouldBe('abcd');
41
    }
42
43 View Code Duplication
    public function it_gets_from_json_x()
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...
44
    {
45
        $request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refresh_token' => 'abcd')));
46
        $request->headers->set('content_type', 'application/x-json');
47
48
        $this->getRefreshToken($request)->shouldBe('abcd');
49
    }
50
51 View Code Duplication
    public function it_gets_from_json_parameter()
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...
52
    {
53
        $request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refresh_token' => 'abcd')));
54
        $request->headers->set('content_type', 'application/json;charset=UTF-8');
55
56
        $this->getRefreshToken($request)->shouldBe('abcd');
57
    }
58
59 View Code Duplication
    public function it_gets_from_query_param_using_camel_case_naming(NameGeneratorInterface $nameGenerator)
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...
60
    {
61
        $nameGenerator->generateName('refresh_token')
62
            ->willReturn('refreshToken');
63
64
        $request = Request::createFromGlobals();
65
        $request->attributes->set('refreshToken', 'abcd');
66
67
        $this->getRefreshToken($request)->shouldBe('abcd');
68
    }
69
70 View Code Duplication
    public function it_gets_from_body_using_camel_case_naming(NameGeneratorInterface $nameGenerator)
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...
71
    {
72
        $nameGenerator->generateName('refresh_token')
73
            ->willReturn('refreshToken');
74
75
        $request = Request::createFromGlobals();
76
        $request->request->set('refreshToken', 'abcd');
77
78
        $this->getRefreshToken($request)->shouldBe('abcd');
79
    }
80
81 View Code Duplication
    public function it_gets_from_json_using_camel_case_naming(NameGeneratorInterface $nameGenerator)
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...
82
    {
83
        $nameGenerator->generateName('refresh_token')
84
            ->willReturn('refreshToken');
85
86
        $request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refreshToken' => 'abcd')));
87
        $request->headers->set('content_type', 'application/json');
88
89
        $this->getRefreshToken($request)->shouldBe('abcd');
90
    }
91
92 View Code Duplication
    public function it_gets_from_json_x_using_camel_case_naming(NameGeneratorInterface $nameGenerator)
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...
93
    {
94
        $nameGenerator->generateName('refresh_token')
95
            ->willReturn('refreshToken');
96
97
        $request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refreshToken' => 'abcd')));
98
        $request->headers->set('content_type', 'application/x-json');
99
100
        $this->getRefreshToken($request)->shouldBe('abcd');
101
    }
102
103 View Code Duplication
    public function it_gets_from_json_parameter_using_camel_case_naming(NameGeneratorInterface $nameGenerator)
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...
104
    {
105
        $nameGenerator->generateName('refresh_token')
106
            ->willReturn('refreshToken');
107
108
        $request = Request::create(null, 'POST', array(), array(), array(), array(), json_encode(array('refreshToken' => 'abcd')));
109
        $request->headers->set('content_type', 'application/json;charset=UTF-8');
110
111
        $this->getRefreshToken($request)->shouldBe('abcd');
112
    }
113
}
114