ActivityProfileApiClient   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

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 0
loc 63
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createOrUpdateDocument() 0 4 1
A createOrReplaceDocument() 0 4 1
A deleteDocument() 0 7 1
A getDocument() 0 10 1
A doStoreActivityProfileDocument() 0 13 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\Model\ActivityProfile;
15
use Xabbuh\XApi\Model\ActivityProfileDocument;
16
17
/**
18
 * Client to access the activity profile API of an xAPI based learning record
19
 * store.
20
 *
21
 * @author Christian Flothmann <[email protected]>
22
 */
23
class ActivityProfileApiClient extends DocumentApiClient implements ActivityProfileApiClientInterface
24
{
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function createOrUpdateDocument(ActivityProfileDocument $document)
29
    {
30
        $this->doStoreActivityProfileDocument('post', $document);
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function createOrReplaceDocument(ActivityProfileDocument $document)
37
    {
38
        $this->doStoreActivityProfileDocument('put', $document);
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44
    public function deleteDocument(ActivityProfile $profile)
45
    {
46
        $this->doDeleteDocument('activities/profile', array(
47
            'activityId' => $profile->getActivity()->getId(),
48
            'profileId' => $profile->getProfileId(),
49
        ));
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function getDocument(ActivityProfile $profile)
56
    {
57
        /** @var \Xabbuh\XApi\Model\DocumentData $documentData */
58
        $documentData = $this->doGetDocument('activities/profile', array(
59
            'activityId' => $profile->getActivity()->getId(),
60
            'profileId' => $profile->getProfileId(),
61
        ));
62
63
        return new ActivityProfileDocument($profile, $documentData);
64
    }
65
66
    /**
67
     * Stores a state document.
68
     *
69
     * @param string                  $method   HTTP method to use
70
     * @param ActivityProfileDocument $document The document to store
71
     */
72
    private function doStoreActivityProfileDocument($method, ActivityProfileDocument $document)
73
    {
74
        $profile = $document->getActivityProfile();
75
        $this->doStoreDocument(
76
            $method,
77
            'activities/profile',
78
            array(
79
                'activityId' => $profile->getActivity()->getId(),
80
                'profileId' => $profile->getProfileId(),
81
            ),
82
            $document
83
        );
84
    }
85
}
86