Completed
Push — master ( c70864...b6d4e5 )
by Dmitry
03:30 queued 27s
created

Trigger::run()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0072

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
rs 9.552
c 0
b 0
f 0
cc 4
nc 4
nop 0
crap 4.0072
1
<?php
2
3
namespace Basis\Job\Module;
4
5
use Exception;
6
7
class Trigger extends Call
8
{
9
    public $space;
10
    public $id;
11
    public $type;
12
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