AutoCloseCommand::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace RexlManu\LaravelTickets\Commands;
5
6
use Illuminate\Console\Command;
7
use RexlManu\LaravelTickets\Models\Ticket;
8
9
/**
10
 * Class AutoCloseCommand
11
 *
12
 * The command checks if a ticket is unanswered a specific time,
13
 * that is in the configuration defined and then close it
14
 *
15
 * @package RexlManu\LaravelTickets\Commands
16
 */
17
class AutoCloseCommand extends Command
18
{
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature = 'tickets:autoclose';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Close any ticket that has become inactive.';
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return int
37
     */
38
    public function handle()
39
    {
40
        Ticket::query()->state([ 'OPEN', 'ANSWERED' ])->where(
41
            'updated_at',
42
            '<',
43
            now()->subDays(config('laravel-tickets.autoclose-days'))
44
        )->each(function (Ticket $ticket) {
45
            $ticket->update([ 'state' => 'CLOSED' ]);
46
        });
47
    }
48
}
49