| 1 |  |  | <?php namespace Maqe\Qwatcher; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Illuminate\Database\Eloquent\Builder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Illuminate\Database\Eloquent\ModelNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Maqe\Qwatcher\Tracks\TracksInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Maqe\Qwatcher\Tracks\Tracks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Carbon\Carbon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class Qwatcher | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     public function __construct() {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * Insert or update Track table depand on TracksInterface sub class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * @param  TracksInterface $tracks      Sub class that implements TracksInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public function tracks(TracksInterface $tracks) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         return $tracks; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * Get the list of the queue track | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @return collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     public function all() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         return $this->transforms(Tracks::all()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * Get the track record by id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param  $id          The track id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @return object | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function getById($id) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         return $this->transform(Tracks::where('id', $id)->firstOrFail()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * Get the track record by current status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @param  $status      The track status | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @return collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function getByStatus($status) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $builder = Tracks::where("queue_at", '>', '0000-00-00 00:00:00'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $methodName = 'filterBy'.ucfirst($status); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         if (method_exists($this, $methodName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             $this->{$methodName}($builder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             throw new \Exception('"'.$status.'" doesn\'t not exist'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         return $this->transforms($builder->get()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * Get the track record by job name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @param  $name        The job name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @return collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function getByJobName($name) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $collecName = str_replace('\\', '%',$name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $condition = "`tracks`.`meta` LIKE '%\"job_name\":\"{$collecName}\"%'"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         return $this->transforms(Tracks::whereRaw($condition)->get()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * Transform records in tracks collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param  Collection $tracks   The tracks collection | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @return Collection           The tracks collection after transform | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     protected function transform($track) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $track->meta = ($track->meta) ? json_decode($track->meta) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $track->payload = ($track->payload) ? json_decode($track->payload) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $track->payload->data->command = ($track->payload->data->command) ? unserialize($track->payload->data->command) : null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         return $track; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * Transform records in tracks collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @param  Collection $tracks   The tracks collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @return Collection           The tracks collection after transform | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     protected function transforms($tracks) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return $tracks->each(function($track) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             $track = $this->transform($track); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      * Filter by process date is not null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |      * - succeed and failed must be null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @param  Builder $builder The tracks builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @return Builder          The query builder with filter applied. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     protected function filterByProcess(Builder $builder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         return $builder->where("process_at", '>', '0000-00-00 00:00:00') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             ->where('succeed_at', '=', '0000-00-00 00:00:00') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             ->where('failed_at', '=', '0000-00-00 00:00:00'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * Filter by succeed date is not null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * - process is not null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * - failed is null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @param  Builder $builder The tracks builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * @return Builder          The query builder with filter applied. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     protected function filterBySucceed(Builder $builder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         return $builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             ->where('succeed_at', '>', '0000-00-00 00:00:00') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             ->where('failed_at', '=', '0000-00-00 00:00:00'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      * Filter by failed date is not null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |      * - succeed is null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |      * @param  Builder $builder The tracks builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |      * @return Builder          The query builder with filter applied. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 142 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 143 |  |  |     protected function filterByFailed(Builder $builder) | 
            
                                                        
            
                                    
            
            
                | 144 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 145 |  |  |         return $builder->where('succeed_at', '=', '0000-00-00 00:00:00') | 
            
                                                        
            
                                    
            
            
                | 146 |  |  |             ->where('failed_at', '>', '0000-00-00 00:00:00'); | 
            
                                                        
            
                                    
            
            
                | 147 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 148 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 149 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: