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.
Passed
Push — 2.0 ( 4b0ab2...40b088 )
by Nico
06:03
created

Content::Delete()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 8.8571
cc 6
eloc 10
nc 6
nop 2
1
<?php
2
namespace Datatrics\API\Modules;
3
4
class Content extends Base
5
{
6
    /**
7
     * Private constructor so only the client can create this
8
     * @param string $apikey
9
     * @param string $projectid
10
     */
11
    public function __construct($apikey, $projectid)
12
    {
13
        parent::__construct($apikey, "/project/" . $projectid . "/content");
14
    }
15
16
    /**
17
     * Get one or multiple contents
18
     * @param string content id, leave null for list of boxes
19
     * @param object Containing query arguments
20
     * @return object Result of the request
21
     */
22
    public function Get($contentId = null, $args = array("limit" => 50, 'type' => 'item', 'itemtype' => 'product'))
23
    {
24
        if ($contentId) {
25
            if (!isset($args['source'])) {
26
                throw new \Exception('Source is required');
27
            }
28
        }
29
        return $contentId == null ? $this->request(self::HTTP_GET, "?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$contentId."?".http_build_query($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->request(self::HTTP_POST, "", $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->request(self::HTTP_PUT, "/".$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->request(self::HTTP_DELETE, "/".$contentId."?".http_build_query($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 UpdateBulk($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->request(self::HTTP_POST, "/bulk", ['items' => $items]);
103
    }
104
}
105