| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace NotificationChannels\Zendesk; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Arr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Zendesk\API\HttpClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Notifications\Notification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class ZendeskChannel | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** @var HttpClient */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** @var array */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     protected $parameters; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  |     /** @param HttpClient $client */ | 
            
                                                                        
                            
            
                                    
            
            
                | 19 | 3 |  |     public function __construct(HttpClient $client) | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 21 | 3 |  |         $this->client = $client; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Send the given notification. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @param mixed $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @param \Illuminate\Notifications\Notification $notification | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      * @throws \NotificationChannels\Zendesk\Exceptions\InvalidConfiguration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * @throws \NotificationChannels\Zendesk\Exceptions\CouldNotSendNotification | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 3 |  |     public function send($notifiable, Notification $notification) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 3 |  |         $this->parameters = $notification->toZendesk($notifiable)->toArray(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 3 |  |         $id = $this->parameters['ticket']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 3 |  |         if (! is_null($id)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  |             return $this->updateTicket($id, $notifiable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 2 |  |         return $this->createNewTicket($notifiable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * Send update ticket request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param mixed $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 | 1 | View Code Duplication |     private function updateTicket($id, $notifiable) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |         $this->prepareUpdateParameters(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 1 |  |             $this->client->tickets()->update($id, $this->parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             throw CouldNotSendNotification::serviceRespondedWithAnError($e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * Send create ticket request. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * @param mixed $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 67 | 2 | View Code Duplication |     private function createNewTicket($notifiable) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 2 |  |         $this->prepareCreateParameter($notifiable); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 2 |  |             $this->client->tickets()->create($this->parameters); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             throw CouldNotSendNotification::serviceRespondedWithAnError($e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 2 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * Prepare the parameters before update request send. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * @param mixed $notifiable | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 1 |  |     public function prepareUpdateParameters() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 1 |  |         unset($this->parameters['subject'], $this->parameters['requester'], $this->parameters['description'], $this->parameters['ticket']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 1 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * Prepare the parameters before create request send. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * @param mixed $notifiable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 2 |  |     private function prepareCreateParameter($notifiable) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         // Check if the requester data is not set | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 2 |  |         if (! isset($this->parameters['requester']['name']) || $this->parameters['requester']['name'] === '') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 1 |  |             $routing = collect($notifiable->routeNotificationFor('Zendesk')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 1 |  |             if (! Arr::has($routing, ['name', 'email'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |                 return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 1 |  |             $this->parameters['requester']['name'] = $routing['name']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 | 1 |  |             $this->parameters['requester']['email'] = $routing['email']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 | 2 |  |         unset($this->parameters['ticket']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 2 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 108 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |  | 
            
                        
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.