RequestTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 25.88 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 22
loc 85
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMethod() 0 5 1
A testGetPath() 0 5 1
A testAuth() 0 8 1
A testHeaders() 11 11 1
A testParams() 11 11 1
A testJson() 0 11 1
A testApiVersion() 0 8 1
A testIsGraphQL() 0 8 1
A testGetUrl() 0 7 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 Postpay\Tests\Http;
4
5
use PHPUnit\Framework\TestCase;
6
use Postpay\Http\Request;
7
use Postpay\Postpay;
8
9
class RequestTest extends TestCase
10
{
11
    public function testGetMethod()
12
    {
13
        $request = new Request('get');
14
        self::assertSame('GET', $request->getMethod());
15
    }
16
17
    public function testGetPath()
18
    {
19
        $request = new Request('GET', '/');
20
        self::assertSame('/', $request->getPath());
21
    }
22
23
    public function testAuth()
24
    {
25
        $request = new Request('GET');
26
        $auth = ['user', 'password'];
27
        $request->setAuth($auth);
28
29
        self::assertSame($auth, $request->getAuth());
30
    }
31
32 View Code Duplication
    public function testHeaders()
0 ignored issues
show
Duplication introduced by mongkok
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');
35
        $headers = ['header' => true];
36
        $request->setHeaders($headers);
37
38
        self::assertSame(
39
            array_intersect($headers, $request->getHeaders()),
40
            $headers
41
        );
42
    }
43
44 View Code Duplication
    public function testParams()
0 ignored issues
show
Duplication introduced by mongkok
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...
45
    {
46
        $request = new Request('GET');
47
        $params = ['param' => true];
48
        $request->setParams($params);
49
50
        self::assertSame(
51
            array_intersect($params, $request->getParams()),
52
            $params
53
        );
54
    }
55
56
    public function testJson()
57
    {
58
        $request = new Request('GET');
59
        $params = ['test' => true];
60
61
        $request->setParams($params);
62
        self::assertEmpty($request->json());
63
64
        $request->setMethod('POST');
65
        self::assertNotEmpty($request->json());
66
    }
67
68
    public function testApiVersion()
69
    {
70
        $request = new Request('GET');
71
        $version = 'v1';
72
        $request->setApiVersion($version);
73
74
        self::assertSame($version, $request->getApiVersion());
75
    }
76
77
    public function testIsGraphQL()
78
    {
79
        $request = new Request('GET');
80
        self::assertFalse($request->isGraphQL());
81
82
        $request->setApiVersion(Postpay::GRAPHQL_VERSION);
83
        self::assertTrue($request->isGraphQL());
84
    }
85
86
    public function testGetUrl()
87
    {
88
        $path = '/test';
89
        $request = new Request('GET', $path);
90
91
        self::assertStringEndsWith($path, $request->getUrl());
92
    }
93
}
94