Completed
Push — master ( 5e9169...e507aa )
by Dmitry
04:13
created

Trigger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 30
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 23 4
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
    public function run()
14
    {
15
        $this->require('space');
16
        $this->require('id');
17
18
        if (!in_array($this->type, ['create', 'update', 'remove'])) {
19
            throw new Exception("Invalid type $this->type");
20
        }
21
22
        $method = 'after'.ucfirst($this->type);
23
24
        $entity = $this->findOrFail($this->space, $this->id);
25
26
        // afterUpdate trigger will be called on save
27
        if ($this->type != 'update') {
28
            if (method_exists($entity, $method)) {
29
                $this->method = $method;
30
                parent::run();
31
            }
32
        }
33
34
        $entity->save();
35
    }
36
}
37