RevertModelEvent::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 18
ccs 8
cts 12
cp 0.6667
crap 3.3332
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Djunehor\EventRevert;
4
5
use Illuminate\Console\Command;
6
7
class RevertModelEvent extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'model:revert {--i|id=}';
15
    /**
16
     * The console command description.
17
     *
18
     * @var string
19
     */
20
    protected $description = 'Revert specific Model Event by specifying the Log ID';
21
22
    /**
23
     * Create a new command instance.
24
     *
25
     * @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...
26
     */
27 3
    public function __construct()
28
    {
29 3
        parent::__construct();
30 3
    }
31
32
    /**
33
     * Execute the console command.
34
     *
35
     * @return void
36
     */
37 2
    public function handle()
38
    {
39 2
        $id = $this->option('id');
40 2
        $log = ModelLog::find($id);
41 2
        if (! $id) {
42
            $this->error('Log not found!');
43
44
            return;
45
        }
46
47 2
        $revert = model_event_revert($log);
48 2
        if (! $revert['status']) {
49
            $this->error($revert['message']);
50
51
            return;
52
        }
53 2
        $this->info("Model Event #$log->id has been reverted successfully");
54 2
    }
55
}
56