Passed
Push — master ( 8f3742...50f570 )
by Darko
08:41
created

PurgeDeletedAccounts   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 1
A __construct() 0 2 1
1
<?php
2
3
namespace App\Jobs;
4
5
use App\Models\User;
6
use Illuminate\Bus\Queueable;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
use Illuminate\Foundation\Bus\Dispatchable;
9
use Illuminate\Queue\InteractsWithQueue;
10
use Illuminate\Queue\SerializesModels;
11
12
class PurgeDeletedAccounts implements ShouldQueue
13
{
14
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\InteractsWithQueue requires some properties which are not provided by App\Jobs\PurgeDeletedAccounts: $failedWith, $releaseDelay
Loading history...
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Jobs\PurgeDeletedAccounts: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
15
16
    /**
17
     * Create a new job instance.
18
     *
19
     * @return void
20
     */
21
    public function __construct()
22
    {
23
        //
24
    }
25
26
    /**
27
     * Execute the job.
28
     *
29
     * Find users that were soft-deleted 6 months ago and permanently delete them.
30
     */
31
    public function handle(): void
32
    {
33
        // Find users that were soft-deleted 6 months ago
34
        User::onlyTrashed()
35
            ->where('deleted_at', '<', now()->subMonths(6))
36
            ->get()
37
            ->each(function ($user) {
38
                $user->forceDelete(); // Permanently delete the user
39
            });
40
    }
41
}
42