DeleteUsers::getList()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace SET\Console\Commands;
4
5
use Carbon\Carbon;
6
use Illuminate\Console\Command;
7
use Illuminate\Database\Eloquent\Collection;
8
use Illuminate\Support\Facades\Storage;
9
use SET\User;
10
11
class DeleteUsers extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'users:purge';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Deletes users on their destroyed date.';
26
27
    protected $destroyed;
28
29
    /**
30
     * Create a new command instance.
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
        $this->destroyed = new Collection();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return DeleteUsers
42
     */
43
    public function handle()
44
    {
45
        $this->setDestroyed();
46
47
        return $this;
48
    }
49
50
    /**
51
     * Return list of users who were destroyed.
52
     *
53
     * @return Collection
54
     */
55
    public function getList()
56
    {
57
        return $this->destroyed;
58
    }
59
60
    public function setDestroyed()
61
    {
62
        $deadmanList = User::where('status', '!=', 'active')
63
            ->where('destroyed_date', '<=', Carbon::today())
64
            ->get();
65
66
        foreach ($deadmanList as $user) {
67
            Storage::deleteDirectory('user_'.$user->id);
68
            $user->delete();
69
        }
70
71
        $this->destroyed = $deadmanList;
72
    }
73
}
74