Completed
Push — master ( dcb869...651674 )
by Dmitry
02:44
created

Trigger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 29
ccs 11
cts 12
cp 0.9167
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 22 4
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Basis\Job;
6
use Exception;
7
8
class Trigger extends Job
9
{
10
    public $space;
11
    public $id;
12
    public $type;
13
14 1
    public function run()
15
    {
16 1
        $this->require('space');
17 1
        $this->require('id');
18
19 1
        if (!in_array($this->type, ['create', 'update', 'remove'])) {
20
            throw new Exception("Invalid type $this->type");
21
        }
22
23 1
        $method = 'after'.ucfirst($this->type);
24
25 1
        $entity = $this->findOrFail($this->space, $this->id);
26
27
        // afterUpdate trigger will be called on save
28 1
        if ($this->type != 'update') {
29 1
            if (method_exists($entity, $method)) {
30 1
                $entity->$method();
31
            }
32
        }
33
34 1
        $entity->save();
35 1
    }
36
}
37