GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 2.0 ( 5e7ce8...036b94 )
by Nico
06:29
created

Content::Update()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
ccs 0
cts 0
cp 0
rs 8.8571
cc 6
eloc 11
nc 6
nop 1
crap 42
1
<?php
2
namespace Datatrics\API\Modules;
3
4
use Datatrics\API\Client;
5
6
class Content extends Base
7
{
8
    /**
9
     * Private constructor so only the client can create this
10
     * @param Client $client
11
     */
12 11
    public function __construct(Client $client)
13
    {
14 11
        parent::__construct($client);
15 11
        $this->SetUrl("/project/" . $this->GetClient()->GetProjectId() . "/content");
16 11
    }
17
18
    /**
19
     * Get one or multiple contents
20
     * @param string content id, leave null for list of boxes
21
     * @param object Containing query arguments
22
     * @return object Result of the request
23
     */
24
    public function Get($contentId = null, $args = array("limit" => 50, 'type' => 'item'))
25
    {
26
        if (is_null($contentId)) {
27
            return $this->GetClient()->Get($this->GetUrl(), $args);
28
        }
29
        return $this->GetClient()->Get($this->GetUrl()."/".$contentId, $args);
30
    }
31
32
    /**
33
     * Create new content
34
     * @param object Containing all the information of a content
35
     * @return object Result of the request
36
     */
37
    public function Create($content)
38
    {
39
        return $this->GetClient()->Post($this->GetUrl(), $content);
40
    }
41
42
    /**
43
     * Create new content
44
     * @param object Containing all the information of a content
45
     * @throws \Exception When contentid, source, type or itemtype is not present
46
     * @return object Result of the request
47
     */
48
    public function Update($content)
49
    {
50
        if (!isset($content['contentid'])) {
51
            throw new \Exception("content must contain a contentid");
52
        }
53
        if (!isset($content['source'])) {
54
            throw new \Exception("content must contain a source");
55
        }
56
        if (!isset($content['type'])) {
57
            throw new \Exception("content must contain a type");
58
        }
59
        if ($content['type'] == 'item') {
60
            if (!isset($content['itemtype'])) {
61
                throw new \Exception("content must contain a itemtype");
62
            }
63
        }
64
        return $this->GetClient()->Put($this->GetUrl()."/".$content['contentid'], $content);
65
    }
66
67
    /**
68
     * Delete a content object by content id
69
     * @param string Id of the content
70
     * @return object Result of the request
71
     */
72
    public function Delete($contentId, $args = array('type' => 'item', 'itemtype' => 'product'))
73
    {
74
        if ($contentId) {
75
            if (!isset($args['source'])) {
76
                throw new \Exception('Source is required');
77
            }
78
            if (!isset($args['type'])) {
79
                throw new \Exception("Type is required");
80
            }
81
            if ($args['type'] == 'item') {
82
                if (!isset($args['itemtype'])) {
83
                    throw new \Exception("Itemtype is required");
84
                }
85
            }
86
        }
87
        return $this->GetClient()->Delete($this->GetUrl()."/".$contentId, $args);
88
    }
89
90
    /**
91
     * Updates a maximum of 50 content items at a time.
92
     * @param array Containing content items with a maximum of 50
93
     * @throws \Exception When more that 50 content items are provided
94
     * @return object Result of the request
95
     */
96
    public function Bulk($items)
97
    {
98
        if (count($items) > 50) {
99
            throw new \Exception("Maximum of 50 content items allowed at a time");
100
        }
101
102
        return $this->GetClient()->Post($this->GetUrl()."/bulk", ['items' => $items]);
103
    }
104
}
105