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.

UsersProfile   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 111
Duplicated Lines 79.28 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 24
lcom 1
cbo 5
dl 88
loc 111
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B get() 38 38 9
C set() 50 50 15

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
3
/*
4
 * This file is part of Slackify.
5
 *
6
 * (c) Strime <[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 Strime\Slackify\Api;
13
14
use Strime\Slackify\Exception\RuntimeException;
15
use Strime\Slackify\Exception\InvalidArgumentException;
16
use GuzzleHttp\Exception\RequestException;
17
18
class UsersProfile extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $user
24
     * @param  bool $include_labels
25
     * @return string
26
     */
27 View Code Duplication
    public function get($user = NULL, $include_labels = NULL) {
0 ignored issues
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...
28
29
        // Check if the type of the variables is valid.
30
        if (!is_string($user) && ($user != NULL)) {
31
            throw new InvalidArgumentException("The type of the user variable is not valid.");
32
        }
33
        if (!is_string($include_labels) && ($include_labels != NULL)) {
34
            throw new InvalidArgumentException("The type of the include_labels variable is not valid.");
35
        }
36
37
        // Set the arguments of the request
38
        $arguments = array();
39
40
        if ($user != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
41
            $arguments["user"] = $user;
42
        }
43
        if ($include_labels != NULL) {
44
            $arguments["include_labels"] = $include_labels;
45
        }
46
47
        $this->setUrl("users.profile.get", $arguments);
48
49
        // Send the request
50
        try {
51
            $client = new \GuzzleHttp\Client();
52
            $json_response = $client->request('GET', $this->getUrl(), []);
53
            $response = json_decode( $json_response->getBody() );
54
        }
55
        catch (RequestException $e) {
56
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
57
        }
58
59
        if($response->{'ok'} === FALSE) {
60
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
61
        }
62
63
        return $json_response->getBody();
64
    }
65
66
67
68
69
    /**
70
     * {@inheritdoc}
71
     *
72
     * @param  string $user
73
     * @param  string $profile
74
     * @param  string $name
75
     * @param  string $value
76
     * @return string
77
     */
78 View Code Duplication
    public function set($user = NULL, $profile = NULL, $name = NULL, $value = NULL) {
0 ignored issues
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...
79
80
        // Check if the type of the variables is valid.
81
        if (!is_string($user) && ($user != NULL)) {
82
            throw new InvalidArgumentException("The type of the user variable is not valid.");
83
        }
84
        if (!is_string($profile) && ($profile != NULL)) {
85
            throw new InvalidArgumentException("The type of the profile variable is not valid.");
86
        }
87
        if (!is_string($name) && ($name != NULL)) {
88
            throw new InvalidArgumentException("The type of the name variable is not valid.");
89
        }
90
        if (!is_string($value) && ($value != NULL)) {
91
            throw new InvalidArgumentException("The type of the value variable is not valid.");
92
        }
93
94
        // Set the arguments of the request
95
        $arguments = array();
96
97
        if ($user != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
98
            $arguments["user"] = $user;
99
        }
100
        if ($profile != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $profile of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
101
            $arguments["profile"] = $profile;
102
        }
103
        if ($name != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $name of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
104
            $arguments["name"] = $name;
105
        }
106
        if ($value != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $value of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
107
            $arguments["value"] = $value;
108
        }
109
110
        $this->setUrl("users.profile.set", $arguments);
111
112
        // Send the request
113
        try {
114
            $client = new \GuzzleHttp\Client();
115
            $json_response = $client->request('GET', $this->getUrl(), []);
116
            $response = json_decode( $json_response->getBody() );
117
        }
118
        catch (RequestException $e) {
119
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
120
        }
121
122
        if($response->{'ok'} === FALSE) {
123
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
124
        }
125
126
        return $json_response->getBody();
127
    }
128
}
129