RequestAuthenticationMiddlewareTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 55.17 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 32
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A itAddsAHeaderWhenAuthenticationHeaderIsNotSet() 13 13 1
A itDoesNotAddAHeaderWhenAuthenticationHeaderIsAlreadySet() 19 19 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 Bunq\Tests\Middleware;
4
5
use Bunq\Middleware\RequestAuthenticationMiddleware;
6
use Bunq\Token\DefaultToken;
7
use Bunq\Token\Token;
8
use GuzzleHttp\Psr7\Request;
9
use PHPUnit\Framework\TestCase;
10
11
final class RequestAuthenticationMiddlewareTest extends TestCase
12
{
13
    /**
14
     * @var Token
15
     */
16
    private $sessionToken;
17
18
    /**
19
     * @var RequestAuthenticationMiddleware
20
     */
21
    private $middleware;
22
23
    public function setUp()
24
    {
25
        $this->sessionToken = DefaultToken::fromString('session-token');
26
        $this->middleware   = new RequestAuthenticationMiddleware($this->sessionToken);
27
    }
28
29
    /**
30
     * @test
31
     */
32 View Code Duplication
    public function itAddsAHeaderWhenAuthenticationHeaderIsNotSet()
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...
33
    {
34
        $request = new Request('GET', 'uri', []);
35
36
        $request = $this->middleware->__invoke($request);
37
38
        $headers         = [
39
            'X-Bunq-Client-Authentication' => 'session-token',
40
        ];
41
        $expectedRequest = new Request('GET', 'uri', $headers, $request->getBody());
42
43
        $this->assertEquals($expectedRequest, $request);
44
    }
45
46
    /**
47
     * @test
48
     */
49 View Code Duplication
    public function itDoesNotAddAHeaderWhenAuthenticationHeaderIsAlreadySet()
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
        $request = new Request(
52
            'GET',
53
                'uri',
54
                [
55
                    'X-Bunq-Client-Authentication' => 'own-session-token',
56
                ]
57
        );
58
59
        $request = $this->middleware->__invoke($request);
60
61
        $headers         = [
62
            'X-Bunq-Client-Authentication' => 'own-session-token',
63
        ];
64
        $expectedRequest = new Request('GET', 'uri', $headers, $request->getBody());
65
66
        $this->assertEquals($expectedRequest, $request);
67
    }
68
}
69
70