AgentProfileApiClient::getDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
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