RevertModelEvent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 73.32%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 11
cts 15
cp 0.7332
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 18 3
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