| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace WrapIt\Helpers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use WrapIt\WrapIt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use WrapIt\Exceptions\WrapItParameterException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use WrapIt\Http\WrapItApiRequester; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use WrapIt\Http\WrapItPushRequester; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use WrapIt\Helpers\Helper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Class WrapItUserHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @package WrapIt | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 15 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  | class WrapItPushHelper extends Helper { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     protected $access_token = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     protected $push_requester; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 12 |  |     public function __construct($wi, $access_token = null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 12 |  |         parent::__construct($wi); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 12 |  |         $this->access_token = $access_token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 12 |  |         $this->push_requester = new WrapItPushRequester($this->domain, $this->getAccessToken()); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 | 12 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 12 |  |     private function getAccessToken() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 12 |  |         if ($this->access_token != null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 6 |  |             return $this->access_token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 6 |  |         $data = $this->api_requester->post("access_token", array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 6 |  |             "client_id" => $this->client_id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 6 |  |             "client_secret" => $this->client_secret, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 3 |  |             "grant_type" => "app_token" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 3 |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 6 |  |         if (isset($data["access_token"])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 6 |  |             $this->access_token = $data["access_token"]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 6 |  |             return $this->access_token; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         } else if (isset($data["error"])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             throw new WrapItParameterException($data["error"]["message"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         throw new WrapItParameterException("Invalid domain or client credentials"); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function sendPush($userid, $data) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $data = $this->push_requester->post("pushservice/$userid", $data); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function getPushTemplate() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         return array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             "categories" => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             "device_types" => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 "mail" => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |                 "sms" => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |                 "browser" => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |                 "phone" => false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             "properties" => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |                 "attribution" => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |                 "app_icon" => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 "hero_image" => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |                 "badge" => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 "sound" => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |                     "UWP" => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                     "Apple" => null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             "title" => null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             "lines" => array(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             "actions" => array() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |  | 
            
                        
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.