AgentProfileApiClient   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 35.62 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 1
cbo 4
dl 26
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A createOrUpdateDocument() 8 8 1
A createOrReplaceDocument() 8 8 1
A deleteDocument() 0 7 1
A getDocument() 10 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
/*
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\Api;
13
14
use Xabbuh\XApi\Client\Request\HandlerInterface;
15
use Xabbuh\XApi\Serializer\ActorSerializerInterface;
16
use Xabbuh\XApi\Serializer\DocumentDataSerializerInterface;
17
use Xabbuh\XApi\Model\AgentProfile;
18
use Xabbuh\XApi\Model\AgentProfileDocument;
19
20
/**
21
 * Client to access the agent profile API of an xAPI based learning record
22
 * store.
23
 *
24
 * @author Christian Flothmann <[email protected]>
25
 */
26
class AgentProfileApiClient extends DocumentApiClient implements AgentProfileApiClientInterface
27
{
28
    /**
29
     * @var ActorSerializerInterface
30
     */
31
    private $actorSerializer;
32
33
    /**
34
     * @param HandlerInterface                $requestHandler         The HTTP request handler
35
     * @param string                          $version                The xAPI version
36
     * @param DocumentDataSerializerInterface $documentDataSerializer The document data serializer
37
     * @param ActorSerializerInterface        $actorSerializer        The actor serializer
38
     */
39
    public function __construct(
40
        HandlerInterface $requestHandler,
41
        $version,
42
        DocumentDataSerializerInterface $documentDataSerializer,
43
        ActorSerializerInterface $actorSerializer
44
    ) {
45
        parent::__construct($requestHandler, $version, $documentDataSerializer);
46
47
        $this->actorSerializer = $actorSerializer;
48
    }
49
50
    /**
51
     * {@inheritDoc}
52
     */
53 View Code Duplication
    public function createOrUpdateDocument(AgentProfileDocument $document)
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...
54
    {
55
        $profile = $document->getAgentProfile();
56
        $this->doStoreDocument('post', 'agents/profile', array(
57
            'agent' => $this->actorSerializer->serializeActor($profile->getAgent()),
58
            'profileId' => $profile->getProfileId(),
59
        ), $document);
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 View Code Duplication
    public function createOrReplaceDocument(AgentProfileDocument $document)
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...
66
    {
67
        $profile = $document->getAgentProfile();
68
        $this->doStoreDocument('put', 'agents/profile', array(
69
            'agent' => $this->actorSerializer->serializeActor($profile->getAgent()),
70
            'profileId' => $profile->getProfileId(),
71
        ), $document);
72
    }
73
74
    /**
75
     * {@inheritDoc}
76
     */
77
    public function deleteDocument(AgentProfile $profile)
78
    {
79
        $this->doDeleteDocument('agents/profile', array(
80
            'agent' => $this->actorSerializer->serializeActor($profile->getAgent()),
81
            'profileId' => $profile->getProfileId(),
82
        ));
83
    }
84
85
    /**
86
     * {@inheritDoc}
87
     */
88 View Code Duplication
    public function getDocument(AgentProfile $profile)
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...
89
    {
90
        /** @var \Xabbuh\XApi\Model\DocumentData $documentData */
91
        $documentData = $this->doGetDocument('agents/profile', array(
92
            'agent' => $this->actorSerializer->serializeActor($profile->getAgent()),
93
            'profileId' => $profile->getProfileId(),
94
        ));
95
96
        return new AgentProfileDocument($profile, $documentData);
97
    }
98
}
99