UpdateAccounts   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 27 5
1
<?php
2
3
namespace App\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use App\Account;
7
8
class UpdateAccounts extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'update:accounts
16
                            {--ci : No progress bar (eg for CI)}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Disable expired accounts';
24
25
    /**
26
     * Create a new command instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct()
31
    {
32
        parent::__construct();
33
    }
34
35
    /**
36
     * Execute the console command.
37
     *
38
     * @return mixed
39
     */
40
    public function handle()
41
    {
42
        $accounts = Account::where('expire', '<=', date('Y-m-d'))
43
                    ->where('status', Account::ACCOUNT_ENABLE)
44
                    ->get();
45
46
        $count = count($accounts);
47
48
        $flagCI = $this->option('ci');
49
        if ($flagCI === false) {
50
          $bar = $this->output->createProgressBar($count);
51
        }
52
53
        foreach ($accounts as $account) {
54
            $account->disable();
55
            if (isset($bar)) {
56
              $bar->advance();
57
            }
58
        }
59
60
        if (isset($bar)) {
61
          $bar->finish();
62
          $this->info("\n");
63
        }
64
65
        $this->info("{$count} accounts disabled");
66
    }
67
}
68