StateApiClient::doStoreStateDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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\StateDocument;
18
use Xabbuh\XApi\Model\State;
19
20
/**
21
 * Client to access the state API of an xAPI based learning record store.
22
 *
23
 * @author Christian Flothmann <[email protected]>
24
 */
25
final class StateApiClient extends DocumentApiClient implements StateApiClientInterface
26
{
27
    /**
28
     * @var ActorSerializerInterface
29
     */
30
    private $actorSerializer;
31
32
    /**
33
     * @param HandlerInterface                $requestHandler         The HTTP request handler
34
     * @param string                          $version                The xAPI version
35
     * @param DocumentDataSerializerInterface $documentDataSerializer The document data serializer
36
     * @param ActorSerializerInterface        $actorSerializer        The actor serializer
37
     */
38 4
    public function __construct(
39
        HandlerInterface $requestHandler,
40
        $version,
41
        DocumentDataSerializerInterface $documentDataSerializer,
42
        ActorSerializerInterface $actorSerializer
43
    ) {
44 4
        parent::__construct($requestHandler, $version, $documentDataSerializer);
45
46 4
        $this->actorSerializer = $actorSerializer;
47 4
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 1
    public function createOrUpdateDocument(StateDocument $document)
53
    {
54 1
        $this->doStoreStateDocument('post', $document);
55 1
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60 1
    public function createOrReplaceDocument(StateDocument $document)
61
    {
62 1
        $this->doStoreStateDocument('put', $document);
63 1
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68 1
    public function deleteDocument(State $state)
69
    {
70 1
        $this->doDeleteDocument('activities/state', array(
71 1
            'activityId' => $state->getActivity()->getId()->getValue(),
72 1
            'agent' => $this->actorSerializer->serializeActor($state->getActor()),
0 ignored issues
show
Deprecated Code introduced by
The method Xabbuh\XApi\Model\State::getActor() has been deprecated with message: since 1.2, to be removed in 4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73 1
            'stateId' => $state->getStateId(),
74
        ));
75 1
    }
76
77
    /**
78
     * {@inheritDoc}
79
     */
80 1
    public function getDocument(State $state)
81
    {
82
        /** @var \Xabbuh\XApi\Model\DocumentData $documentData */
83 1
        $documentData = $this->doGetDocument('activities/state', array(
84 1
            'activityId' => $state->getActivity()->getId()->getValue(),
85 1
            'agent' => $this->actorSerializer->serializeActor($state->getActor()),
0 ignored issues
show
Deprecated Code introduced by
The method Xabbuh\XApi\Model\State::getActor() has been deprecated with message: since 1.2, to be removed in 4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
86 1
            'stateId' => $state->getStateId(),
87
        ));
88
89 1
        return new StateDocument($state, $documentData);
90
    }
91
92
    /**
93
     * Stores a state document.
94
     *
95
     * @param string        $method   HTTP method to use
96
     * @param StateDocument $document The document to store
97
     */
98 2
    private function doStoreStateDocument($method, StateDocument $document)
99
    {
100 2
        $state = $document->getState();
101 2
        $this->doStoreDocument(
102 2
            $method,
103 2
            'activities/state',
104
            array(
105 2
                'activityId' => $state->getActivity()->getId()->getValue(),
106 2
                'agent' => $this->actorSerializer->serializeActor($state->getActor()),
0 ignored issues
show
Deprecated Code introduced by
The method Xabbuh\XApi\Model\State::getActor() has been deprecated with message: since 1.2, to be removed in 4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
107 2
                'stateId' => $state->getStateId(),
108
            ),
109 2
            $document
110
        );
111 2
    }
112
}
113