Completed
Push — master ( fee0f1...0dcf6f )
by Emmanuel
02:14
created

AutoCloseCommand   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 1
1
<?php
2
3
4
namespace RexlManu\LaravelTickets\Commands;
5
6
use Illuminate\Console\Command;
7
use RexlManu\LaravelTickets\Models\Ticket;
8
9
class AutoCloseCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'tickets:autoclose';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Close any ticket that has become inactive.';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return int
29
     */
30
    public function handle()
31
    {
32
        Ticket::query()->state([ 'OPEN', 'ANSWERED' ])->where(
33
            'updated_at',
34
            '<',
35
            now()->subDays(config('laravel-tickets.autoclose-days'))
36
        )->each(function (Ticket $ticket) {
37
            $ticket->update([ 'state' => 'CLOSED' ]);
38
        });
39
    }
40
}
41