GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

HeaderTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 14.67 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 11
loc 75
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testSetParameter() 0 10 1
A testSetCriticalParameter() 0 17 1
A testFindParameterByName() 11 11 1
A testGetParameters() 0 4 1
A testJsonSerialize() 0 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 Emarref\Jwt\Token;
4
5
use Emarref\Jwt\HeaderParameter;
6
7
class HeaderTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject
11
     */
12
    private $parameters;
13
14
    /**
15
     * @var HeaderStub
16
     */
17
    private $header;
18
19
    public function setUp()
20
    {
21
        $this->parameters = $this->getMockBuilder('Emarref\Jwt\Token\PropertyList')->getMock();
22
        $this->header     = new HeaderStub($this->parameters);
23
    }
24
25
    public function testSetParameter()
26
    {
27
        $parameter = new HeaderParameter\Custom('name', 'value');
28
29
        $this->parameters->expects($this->once())
30
            ->method('setProperty')
31
            ->with($parameter);
32
33
        $this->header->setParameter($parameter);
34
    }
35
36
    public function testSetCriticalParameter()
37
    {
38
        $parameter = new HeaderParameter\Custom('name', 'value');
39
40
        $this->parameters->expects($this->exactly(2))
41
             ->method('setProperty');
42
43
        $this->parameters->expects($this->at(0))
44
            ->method('setProperty')
45
            ->with($parameter);
46
47
        $this->parameters->expects($this->once())
48
            ->method('getIterator')
49
            ->will($this->returnValue(new \ArrayObject([$parameter])));
50
51
        $this->header->setParameter($parameter, true);
52
    }
53
54 View Code Duplication
    public function testFindParameterByName()
55
    {
56
        $parameter = new HeaderParameter\Custom('name', 'value');
57
58
        $this->parameters->expects($this->exactly(2))
59
            ->method('getIterator')
60
            ->will($this->returnValue(new \ArrayObject([$parameter])));
61
62
        $this->assertSame($parameter, $this->header->findParameterByName('name'));
63
        $this->assertNull($this->header->findParameterByName('none'));
64
    }
65
66
    public function testGetParameters()
67
    {
68
        $this->assertSame($this->parameters, $this->header->getParameters());
69
    }
70
71
    public function testJsonSerialize()
72
    {
73
        $expectedJson = '{"whatever":true}';
74
75
        $this->parameters->expects($this->once())
76
            ->method('jsonSerialize')
77
            ->will($this->returnValue($expectedJson));
78
79
        $this->assertSame($expectedJson, $this->header->jsonSerialize());
80
    }
81
}
82