Completed
Push — master ( c4513b...cc10a3 )
by Harry
03:02
created

RequestTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 80
Duplicated Lines 30 %

Coupling/Cohesion

Components 3
Dependencies 2

Importance

Changes 0
Metric Value
dl 24
loc 80
rs 10
c 0
b 0
f 0
wmc 10
lcom 3
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testInterface() 0 5 1
A testGetRpcId() 8 8 1
A testGetRpcIdIsNull() 0 6 1
A testGetRpcMethod() 8 8 1
A testGetRpcMethodIsNull() 0 6 1
A testGetRpcParams() 0 8 1
A testGetRpcParamsIsNull() 0 6 1
A testGetRpcVersion() 8 8 1
A testGetRpcVersionIsNull() 0 6 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
 * This file is part of Guzzle HTTP JSON-RPC
4
 *
5
 * Copyright (c) 2014 Nature Delivered Ltd. <http://graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @see  http://github.com/graze/guzzle-jsonrpc/blob/master/LICENSE
11
 * @link http://github.com/graze/guzzle-jsonrpc
12
 */
13
namespace Graze\GuzzleHttp\JsonRpc\Message;
14
15
use Graze\GuzzleHttp\JsonRpc\ClientInterface;
16
use Graze\GuzzleHttp\JsonRpc\Test\UnitTestCase;
17
18
class RequestTest extends UnitTestCase
19
{
20
    /** @var mixed */
21
    private $stream;
22
23
    public function setUp()
24
    {
25
        $this->stream = $this->mockStream();
26
    }
27
28
    public function testInterface()
29
    {
30
        $this->assertInstanceOf('Graze\GuzzleHttp\JsonRpc\Message\RequestInterface', new Request('foo', 'bar'));
31
        $this->assertInstanceOf('Psr\Http\Message\RequestInterface', new Request('foo', 'bar'));
32
    }
33
34 View Code Duplication
    public function testGetRpcId()
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...
35
    {
36
        $request = new Request('foo', 'bar', [], json_encode([
37
            'id' => 123
38
        ]));
39
40
        $this->assertEquals(123, $request->getRpcId());
41
    }
42
43
    public function testGetRpcIdIsNull()
44
    {
45
        $request = new Request('foo', 'bar');
46
47
        $this->assertNull($request->getRpcId());
48
    }
49
50 View Code Duplication
    public function testGetRpcMethod()
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...
51
    {
52
        $request = new Request('foo', 'bar', [], json_encode([
53
            'method' => 'foo'
54
        ]));
55
56
        $this->assertEquals('foo', $request->getRpcMethod());
57
    }
58
59
    public function testGetRpcMethodIsNull()
60
    {
61
        $request = new Request('foo', 'bar');
62
63
        $this->assertNull($request->getRpcMethod());
64
    }
65
66
    public function testGetRpcParams()
67
    {
68
        $request = new Request('foo', 'bar', [], json_encode([
69
            'params' => ['foo'=>'bar']
70
        ]));
71
72
        $this->assertEquals(['foo'=>'bar'], $request->getRpcParams());
73
    }
74
75
    public function testGetRpcParamsIsNull()
76
    {
77
        $request = new Request('foo', 'bar');
78
79
        $this->assertNull($request->getRpcParams());
80
    }
81
82 View Code Duplication
    public function testGetRpcVersion()
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...
83
    {
84
        $request = new Request('foo', 'bar', [], json_encode([
85
            'jsonrpc' => 'foo'
86
        ]));
87
88
        $this->assertEquals('foo', $request->getRpcVersion());
89
    }
90
91
    public function testGetRpcVersionIsNull()
92
    {
93
        $request = new Request('foo', 'bar');
94
95
        $this->assertNull($request->getRpcVersion());
96
    }
97
}
98