| 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 Reactions extends AbstractApi | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param  string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @param  string $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @param  string $file_comment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @param  string $channel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param  float $timestamp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @return Reactions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 30 |  | View Code Duplication |     public function add($name, $file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         // Check if the type of the variables is valid. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         if (!is_string($name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |             throw new InvalidArgumentException("The type of the name variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         if (($file != NULL) && !is_string($file)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             throw new InvalidArgumentException("The type of the file variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         if (($file_comment != NULL) && !is_string($file_comment)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             throw new InvalidArgumentException("The type of the file_comment variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         if (($channel != NULL) && !is_string($channel)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             throw new InvalidArgumentException("The type of the channel variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         if (($timestamp != NULL) && !is_float($timestamp)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             throw new InvalidArgumentException("The type of the timestamp variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         // Set the arguments of the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $arguments = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             "name" => $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         if ($file != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $arguments["file"] = $file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         if ($file_comment != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $arguments["file_comment"] = $file_comment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         if ($channel != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             $arguments["channel"] = $channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         if ($timestamp != NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $arguments["timestamp"] = (float)$timestamp; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->setUrl("reactions.add", $arguments); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         // Send the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             $client = new \GuzzleHttp\Client(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             $json_response = $client->request('GET', $this->getUrl(), []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             $response = json_decode( $json_response->getBody() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         catch (RequestException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         if($response->{'ok'} === FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @param  string $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @param  string $file_comment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      * @param  string $channel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param  float $timestamp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param  boolean $full | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @return Reactions | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |     public function get($file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL, $full = NULL) { | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |         // Check if the type of the variables is valid. | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |         if (($file != NULL) && !is_string($file)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |             throw new InvalidArgumentException("The type of the file variable is not valid."); | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |         if (($file_comment != NULL) && !is_string($file_comment)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |             throw new InvalidArgumentException("The type of the file_comment variable is not valid."); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |         if (($channel != NULL) && !is_string($channel)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |             throw new InvalidArgumentException("The type of the channel variable is not valid."); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |         if (($timestamp != NULL) && !is_float($timestamp)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |             throw new InvalidArgumentException("The type of the timestamp variable is not valid."); | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         if (($full != NULL) && !is_bool($full)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |             throw new InvalidArgumentException("The type of the full variable is not valid."); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |         // Set the arguments of the request | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |         $arguments = array(); | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |         if ($file != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |             $arguments["file"] = $file; | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |         if ($file_comment != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |             $arguments["file_comment"] = $file_comment; | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |         if ($channel != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |             $arguments["channel"] = $channel; | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |         if ($timestamp != NULL) { | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |             $arguments["timestamp"] = (string)$timestamp; | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |         if ($full != NULL) { | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |             $arguments["full"] = $full; | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |         $this->setUrl("reactions.get", $arguments); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |         // Send the request | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |             $client = new \GuzzleHttp\Client(); | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             $json_response = $client->request('GET', $this->getUrl(), []); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |             $response = json_decode( $json_response->getBody() ); | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         catch (RequestException $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |             throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |         if($response->{'ok'} === FALSE) { | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |         return $json_response->getBody(); | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |      * @param  string $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |      * @param  boolean $full | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |      * @param  string $count | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |      * @param  string $page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |      * @return Reactions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     public function list_reactions($user = NULL, $full = NULL, $count = 100, $page = 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |         // Check if the type of the variables is valid. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |         if (($user != NULL) && !is_string($user)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |             throw new InvalidArgumentException("The type of the user variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         if (($full != NULL) && !is_bool($full)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |             throw new InvalidArgumentException("The type of the full variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |         if (!is_integer($count)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |             throw new InvalidArgumentException("The type of the count variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         if (!is_integer($page)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |             throw new InvalidArgumentException("The type of the page variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         // Set the arguments of the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $arguments = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             "count" => $count, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |             "page" => $page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         if($user != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             $arguments["user"] = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         if($full != NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             $arguments["full"] = $full; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $this->setUrl("reactions.list"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         // Send the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |             $client = new \GuzzleHttp\Client(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |             $json_response = $client->request('GET', $this->getUrl(), []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |             $response = json_decode( $json_response->getBody() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         catch (RequestException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         if($response->{'ok'} === FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |             throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         return $json_response->getBody(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |      * @param  string $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |      * @param  string $file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |      * @param  string $file_comment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |      * @param  string $channel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |      * @param  float $timestamp | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |      * @return Reactions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 229 |  | View Code Duplication |     public function remove($name, $file = NULL, $file_comment = NULL, $channel = NULL, $timestamp = NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         // Check if the type of the variables is valid. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         if (!is_string($name)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |             throw new InvalidArgumentException("The type of the name variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         if (($file != NULL) && !is_string($file)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |             throw new InvalidArgumentException("The type of the file variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         if (($file_comment != NULL) && !is_string($file_comment)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             throw new InvalidArgumentException("The type of the file_comment variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |         if (($channel != NULL) && !is_string($channel)) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |             throw new InvalidArgumentException("The type of the channel variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |         if (($timestamp != NULL) && !is_float($timestamp)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |             throw new InvalidArgumentException("The type of the timestamp variable is not valid."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         // Set the arguments of the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         $arguments = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |             "name" => $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |         if ($file != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |             $arguments["file"] = $file; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |         if ($file_comment != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |             $arguments["file_comment"] = $file_comment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         if ($channel != NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |             $arguments["channel"] = $channel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         if ($timestamp != NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |             $arguments["timestamp"] = (string)$timestamp; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |         $this->setUrl("reactions.remove", $arguments); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |         // Send the request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |             $client = new \GuzzleHttp\Client(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |             $json_response = $client->request('GET', $this->getUrl(), []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |             $response = json_decode( $json_response->getBody() ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |         catch (RequestException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |             throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         if($response->{'ok'} === FALSE) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |             throw new RuntimeException('The request to the API failed: '.$response->{'error'}."."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 284 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 285 |  |  |  | 
            
                        
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.