| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Soved\Laravel\Gdpr\Jobs\Cleanup\Strategies; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\User; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Carbon\Carbon; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Database\Eloquent\Collection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Soved\Laravel\Gdpr\Events\GdprInactiveUser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Soved\Laravel\Gdpr\Jobs\Cleanup\CleanupStrategy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Soved\Laravel\Gdpr\Events\GdprInactiveUserDeleted; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class DefaultStrategy extends CleanupStrategy | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |      * Execute cleanup strategy. | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      * @param  \Illuminate\Database\Eloquent\Collection  $users | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     public function execute(Collection $users) | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |         $config = $this->config->get('gdpr.cleanup.defaultStrategy'); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |         // Users are considered inactive if their last activity is older than this timestamp | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $inactivity = Carbon::now() | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             ->subMonths($config['keepInactiveUsersForMonths']); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->notifyInactiveUsers( | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |             $inactivity, | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             $config['notifyUsersDaysBeforeDeletion'], | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             $users | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->deleteInactiveUsers($inactivity, $users); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * Notify inactive users about their deletion. | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |      * @param  \Carbon\Carbon  $inactivity | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @param  int  $notificationThreshold | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @param  \Illuminate\Database\Eloquent\Collection  $users | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     private function notifyInactiveUsers( | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         Carbon $inactivity, | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |         int $notificationThreshold, | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         Collection $users | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $users->filter( | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             function (User $user) use ($inactivity, $notificationThreshold) { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 return $user->last_activity->diffInDays($inactivity) | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                     === $notificationThreshold; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         )->each(function (User $user) { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             event(new GdprInactiveUser($user)); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         }); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * Delete inactive users. | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      * @param  \Carbon\Carbon  $inactivity | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      * @param  \Illuminate\Database\Eloquent\Collection  $users | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     private function deleteInactiveUsers( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         Carbon $inactivity, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         Collection $users | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $users->filter(function (User $user) use ($inactivity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             return $user->last_activity < $inactivity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         })->each(function (User $user) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $user->delete(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |             event(new GdprInactiveUserDeleted($user)); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 77 |  |  |         }); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths