StateApiClientTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 111
Duplicated Lines 81.08 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 1
cbo 9
dl 90
loc 111
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 10 10 1
A testCreateOrUpdateDocument() 20 20 1
A testCreateOrReplaceDocument() 20 20 1
A testDeleteDocument() 16 16 1
B testGetDocument() 24 24 1
A createState() 0 8 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
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Client\Tests\Api;
13
14
use Xabbuh\XApi\Client\Api\StateApiClient;
15
use Xabbuh\XApi\DataFixtures\DocumentFixtures;
16
use Xabbuh\XApi\Model\Activity;
17
use Xabbuh\XApi\Model\Agent;
18
use Xabbuh\XApi\Model\State;
19
use Xabbuh\XApi\Serializer\ActorSerializer;
20
use Xabbuh\XApi\Serializer\DocumentDataSerializer;
21
22
/**
23
 * @author Christian Flothmann <[email protected]>
24
 */
25
class StateApiClientTest extends ApiClientTest
26
{
27
    /**
28
     * @var StateApiClient
29
     */
30
    private $client;
31
32 View Code Duplication
    protected function setUp()
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
        parent::setUp();
35
        $this->client = new StateApiClient(
36
            $this->requestHandler,
37
            '1.0.1',
38
            new DocumentDataSerializer($this->serializer),
39
            new ActorSerializer($this->serializer)
40
        );
41
    }
42
43 View Code Duplication
    public function testCreateOrUpdateDocument()
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
        $document = DocumentFixtures::getStateDocument();
46
47
        $this->validateStoreApiCall(
48
            'post',
49
            'activities/state',
50
            array(
51
                'activityId' => 'activity-id',
52
                'agent' => 'agent-as-json',
53
                'stateId' => 'state-id',
54
            ),
55
            204,
56
            '',
57
            $document->getData(),
58
            array(array('data' => $document->getState()->getActor(), 'result' => 'agent-as-json'))
59
        );
60
61
        $this->client->createOrUpdateDocument($document);
62
    }
63
64 View Code Duplication
    public function testCreateOrReplaceDocument()
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...
65
    {
66
        $document = DocumentFixtures::getStateDocument();
67
68
        $this->validateStoreApiCall(
69
            'put',
70
            'activities/state',
71
            array(
72
                'activityId' => 'activity-id',
73
                'agent' => 'agent-as-json',
74
                'stateId' => 'state-id',
75
            ),
76
            204,
77
            '',
78
            $document->getData(),
79
            array(array('data' => $document->getState()->getActor(), 'result' => 'agent-as-json'))
80
        );
81
82
        $this->client->createOrReplaceDocument($document);
83
    }
84
85 View Code Duplication
    public function testDeleteDocument()
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...
86
    {
87
        $state = $this->createState();
88
89
        $this->validateDeleteDocumentCall(
90
            'activities/state',
91
            array(
92
                'activityId' => 'activity-id',
93
                'agent' => 'agent-as-json',
94
                'stateId' => 'state-id',
95
            ),
96
            array(array('data' => $state->getActor(), 'result' => 'agent-as-json'))
97
        );
98
99
        $this->client->deleteDocument($state);
100
    }
101
102 View Code Duplication
    public function testGetDocument()
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...
103
    {
104
        $document = DocumentFixtures::getStateDocument();
105
        $state = $document->getState();
106
107
        $this->validateRetrieveApiCall(
108
            'get',
109
            'activities/state',
110
            array(
111
                'activityId' => 'activity-id',
112
                'agent' => 'agent-as-json',
113
                'stateId' => 'state-id',
114
            ),
115
            200,
116
            'DocumentData',
117
            $document->getData(),
118
            array(array('data' => $state->getActor(), 'result' => 'agent-as-json'))
119
        );
120
121
        $document = $this->client->getDocument($state);
122
123
        $this->assertInstanceOf('Xabbuh\XApi\Model\StateDocument', $document);
124
        $this->assertEquals($state, $document->getState());
125
    }
126
127
    private function createState()
128
    {
129
        $agent = new Agent('mailto:[email protected]');
130
        $activity = new Activity('activity-id');
131
        $state = new State($activity, $agent, 'state-id');
132
133
        return $state;
134
    }
135
}
136