Conditions | 4 |
Paths | 4 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 4.0072 |
Changes | 0 |
1 | <?php |
||
13 | 1 | public function run() |
|
14 | { |
||
15 | 1 | $this->require('space'); |
|
16 | 1 | $this->require('id'); |
|
17 | |||
18 | 1 | if (!in_array($this->type, ['create', 'update', 'remove'])) { |
|
19 | throw new Exception("Invalid type $this->type"); |
||
20 | } |
||
21 | |||
22 | 1 | $method = 'after'.ucfirst($this->type); |
|
23 | |||
24 | 1 | $entity = $this->findOrFail($this->space, $this->id); |
|
25 | |||
26 | // afterUpdate trigger will be called on save |
||
27 | 1 | if ($this->type != 'update') { |
|
28 | 1 | if (method_exists($entity, $method)) { |
|
29 | 1 | $this->method = $method; |
|
30 | 1 | parent::run(); |
|
31 | } |
||
32 | } |
||
33 | |||
34 | 1 | $entity->save(); |
|
35 | 1 | } |
|
36 | } |
||
37 |