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 — master ( 4cd0f0...30655b )
by Romain
04:55
created

FilesComments::edit()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 38
Code Lines 21

Duplication

Lines 38
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 38
loc 38
rs 8.439
cc 6
eloc 21
nc 8
nop 3
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 FilesComments extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $file
24
     * @param  string $comment
25
     * @param  string $channel
26
     * @return FilesComments
27
     */
28 View Code Duplication
    public function add($file, $comment, $channel = 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...
29
30
        // Check if the type of the variables is valid.
31
        if (!is_string($file)) {
32
            throw new InvalidArgumentException("The type of the file variable is not valid.");
33
        }
34
        if (!is_string($comment)) {
35
            throw new InvalidArgumentException("The type of the comment variable is not valid.");
36
        }
37
        if (($channel != NULL) && !is_string($channel)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $channel of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
38
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
39
        }
40
41
        // Set the arguments of the request
42
        $arguments = array(
43
            "file" => $file,
44
            "comment" => $comment
45
        );
46
47
        if($channel != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $channel of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
48
            $arguments["channel"] = $channel;
49
        }
50
51
        $this->setUrl("files.comments.add", $arguments);
52
53
        // Send the request
54
        try {
55
            $client = new \GuzzleHttp\Client();
56
            $json_response = $client->request('GET', $this->getUrl(), []);
57
            $response = json_decode( $json_response->getBody() );
58
        }
59
        catch (RequestException $e) {
60
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
61
        }
62
63
        if($response->{'ok'} === FALSE) {
64
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
65
        }
66
67
        return $json_response->getBody();
68
    }
69
70
71
    /**
72
     * {@inheritdoc}
73
     *
74
     * @param  string $file
75
     * @param  string $id
76
     * @return FilesComments
77
     */
78
    public function delete($file, $id) {
79
80
        // Check if the type of the variables is valid.
81
        if (!is_string($file)) {
82
            throw new InvalidArgumentException("The type of the file variable is not valid.");
83
        }
84
        if (!is_string($id)) {
85
            throw new InvalidArgumentException("The type of the id variable is not valid.");
86
        }
87
88
        // Set the arguments of the request
89
        $arguments = array(
90
            "file" => $file,
91
            "id" => $id
92
        );
93
94
        $this->setUrl("files.comments.delete", $arguments);
95
96
        // Send the request
97
        try {
98
            $client = new \GuzzleHttp\Client();
99
            $json_response = $client->request('GET', $this->getUrl(), []);
100
            $response = json_decode( $json_response->getBody() );
101
        }
102
        catch (RequestException $e) {
103
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
104
        }
105
106
        if($response->{'ok'} === FALSE) {
107
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
108
        }
109
110
        return $this;
111
    }
112
113
114
    /**
115
     * {@inheritdoc}
116
     *
117
     * @param  string $file
118
     * @param  string $id
119
     * @param  string $comment
120
     * @return FilesComments
121
     */
122 View Code Duplication
    public function edit($file, $id, $comment) {
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...
123
124
        // Check if the type of the variables is valid.
125
        if (!is_string($file)) {
126
            throw new InvalidArgumentException("The type of the file variable is not valid.");
127
        }
128
        if (!is_string($id)) {
129
            throw new InvalidArgumentException("The type of the id variable is not valid.");
130
        }
131
        if (!is_string($comment)) {
132
            throw new InvalidArgumentException("The type of the comment variable is not valid.");
133
        }
134
135
        // Set the arguments of the request
136
        $arguments = array(
137
            "file" => $file,
138
            "id" => $id,
139
            "comment" => $comment
140
        );
141
142
        $this->setUrl("files.comments.edit", $arguments);
143
144
        // Send the request
145
        try {
146
            $client = new \GuzzleHttp\Client();
147
            $json_response = $client->request('GET', $this->getUrl(), []);
148
            $response = json_decode( $json_response->getBody() );
149
        }
150
        catch (RequestException $e) {
151
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
152
        }
153
154
        if($response->{'ok'} === FALSE) {
155
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
156
        }
157
158
        return $json_response->getBody();
159
    }
160
}
161