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 ( fb4bbc...dcdbd9 )
by Nico
29:09 queued 02:20
created

Box   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 98
Duplicated Lines 16.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 1
dl 16
loc 98
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A Get() 0 4 2
A GetCode() 0 4 1
A GetVersion() 0 4 2
A Create() 0 4 1
A Delete() 0 4 1
A Update() 8 8 2
A UpdateVersion() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Datatrics\API\Modules;
3
4
class Box 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 . "/box");
14
    }
15
16
    /**
17
     * Get one or multiple boxes
18
     * @param string box 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($boxId = null, $args = array("limit" => 50))
23
    {
24
        return $boxId == null ? $this->request(self::HTTP_GET, "?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$boxId."?".http_build_query($args));
25
    }
26
27
    /**
28
     * Get all box codes
29
     * @param string box id
30
     * @param object Containing query arguments
31
     * @return object Result of the request
32
     */
33
    public function GetCode($boxId, $args = array("limit" => 50))
34
    {
35
        return $this->request(self::HTTP_GET, "/".$boxId."/code?".http_build_query($args));
36
    }
37
38
    /**
39
     * Get one or multiple versions of a box
40
     * @param string box id
41
     * @param string version id, leave null for list of versions
42
     * @param object Containing query arguments
43
     * @return object Result of the request
44
     */
45
    public function GetVersion($boxId, $versionId = null, $args = array("limit" => 50))
46
    {
47
        return $versionId == null ? $this->request(self::HTTP_GET, "/".$boxId."/version?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$boxId."/version/".$versionId."?".http_build_query($args));
48
    }
49
50
    /**
51
     * Create new box
52
     * @param object Containing all the information of a box
53
     * @return object Result of the request
54
     */
55
    public function Create($box)
56
    {
57
        return $this->request(self::HTTP_POST, "", $box);
58
    }
59
60
    /**
61
     * Delete a box version by version id
62
     * @param string Id of the box
63
     * @param string Id of the version to be deleted
64
     * @return object Result of the request
65
     */
66
    public function Delete($boxId, $versionId)
67
    {
68
        return $this->request(self::HTTP_DELETE, "/".$boxId."/version/".$versionId);
69
    }
70
71
    /**
72
     * Update a box
73
     * @param object Box containing the boxid and fields that need to be updated
74
     * @throws \Exception When boxid is not present
75
     * @return object Result of the request
76
     */
77 View Code Duplication
    public function Update($box)
1 ignored issue
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...
78
    {
79
        if (!isset($box['boxid'])) {
80
            throw new \Exception("box must contain a boxid");
81
        }
82
83
        return $this->request(self::HTTP_PUT, "/".$box['boxid'], $box);
84
    }
85
86
    /**
87
     * Update a box
88
     * @param string Id of the box
89
     * @param object Version containing the version and fields that need to be updated
90
     * @throws \Exception When versionid is not present
91
     * @return object Result of the request
92
     */
93 View Code Duplication
    public function UpdateVersion($boxid, $version)
1 ignored issue
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...
94
    {
95
        if (!isset($version['versionid'])) {
96
            throw new \Exception("version must contain a versionid");
97
        }
98
99
        return $this->request(self::HTTP_PUT, "/".$boxid."/version/".$version['versionid'], $version);
100
    }
101
}
102