| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * Created by PhpStorm. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * User: Matthew | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Date: 21/04/2016 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Time: 10:23 AM | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | namespace Freshdesk\Resources\Traits; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | trait MonitorTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * @param null $end string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     abstract protected function endpoint($end = null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @return \Freshdesk\Api | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     abstract protected function api(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * Monitor the resource for the given user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @throws \Freshdesk\Exceptions\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @throws \Freshdesk\Exceptions\ApiException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @throws \Freshdesk\Exceptions\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @throws \Freshdesk\Exceptions\ConflictingStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @throws \Freshdesk\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @throws \Freshdesk\Exceptions\RateLimitExceededException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @throws \Freshdesk\Exceptions\MethodNotAllowedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @throws \Freshdesk\Exceptions\ValidationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 43 |  | View Code Duplication |     public function monitor($id, $userId) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $data = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             'user_id' => $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         return $this->api()->request('POST', $this->endpoint($id . '/follow'), $data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * Unmonitor a resource for the given user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @throws \Freshdesk\Exceptions\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @throws \Freshdesk\Exceptions\ApiException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @throws \Freshdesk\Exceptions\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @throws \Freshdesk\Exceptions\ConflictingStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @throws \Freshdesk\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @throws \Freshdesk\Exceptions\RateLimitExceededException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @throws \Freshdesk\Exceptions\MethodNotAllowedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @throws \Freshdesk\Exceptions\ValidationException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                        
                            
            
                                                                    
                                                                                                        
            
            
                | 69 |  | View Code Duplication |     public function unmonitor($id, $userId) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         $query = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             'user_id' => $userId | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |         return $this->api()->request('POST', $this->endpoint($id . '/follow'), null, $query); | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * UnMonitor a forum for the given user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param int $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @throws \Freshdesk\Exceptions\AccessDeniedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * @throws \Freshdesk\Exceptions\ApiException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @throws \Freshdesk\Exceptions\AuthenticationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @throws \Freshdesk\Exceptions\ConflictingStateException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @throws \Freshdesk\Exceptions\NotFoundException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * @throws \Freshdesk\Exceptions\RateLimitExceededException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedContentTypeException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @throws \Freshdesk\Exceptions\MethodNotAllowedException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      * @throws \Freshdesk\Exceptions\ValidationException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 95 |  | View Code Duplication |     public function monitorStatus($id, $userId) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $query = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             'user_id' => $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         return $this->api()->request('GET', $this->endpoint($id . '/follow'), null, $query); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 103 |  |  | } | 
            
                        
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.