Trigger   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 30
ccs 12
cts 13
cp 0.9231
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 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