Completed
Push — master ( 5632ee...e13227 )
by Dmitry
03:38
created

Job   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 57.58%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 14
c 3
b 0
f 2
lcom 2
cbo 1
dl 0
loc 73
ccs 19
cts 33
cp 0.5758
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A confirm() 0 11 3
A create() 0 4 1
A dispatch() 0 4 1
A fire() 0 4 1
A get() 0 4 1
A find() 0 4 1
A findOrCreate() 0 4 1
A findOne() 0 4 1
A findOrFail() 0 4 1
A remove() 0 4 1
A __debugInfo() 0 6 1
1
<?php
2
3
namespace Basis;
4
5
use Exception;
6
use Tarantool\Mapper\Mapper;
7
use Tarantool\Mapper\Entity;
8
9
abstract class Job
10
{
11
    protected $app;
12
13 7
    public function __construct(Application $app)
14
    {
15 7
        $this->app = $app;
16 7
    }
17
18
    protected function confirm($message)
19
    {
20
        $hash = md5($message);
21
        if (!is_array($this->_confirmations) || !in_array($hash, $this->_confirmations)) {
0 ignored issues
show
Bug introduced by
The property _confirmations does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
            throw new Exception(json_encode([
23
                'type' => 'confirm',
24
                'message' => $message,
25
                'hash' => $hash
26
            ]));
27
        }
28
    }
29
30 1
    public function create(string $space, array $data) : Entity
31
    {
32 1
        return $this->get(Mapper::class)->create($space, $data);
33
    }
34
35 1
    public function dispatch(string $job, array $params = [], string $service = null)
36
    {
37 1
        return $this->app->dispatch($job, $params, $service);
38
    }
39
40
    public function fire(string $event, array $context)
41
    {
42
        return $this->get(Event::class)->fire($event, $context);
43
    }
44
45 1
    public function get(string $class)
46
    {
47 1
        return $this->app->get($class);
48
    }
49
50 1
    public function find(string $space, $params = []) : array
51
    {
52 1
        return $this->get(Mapper::class)->find($space, $params);
53
    }
54
55 1
    public function findOrCreate(string $space, $params = []) : Entity
56
    {
57 1
        return $this->get(Mapper::class)->findOrCreate($space, $params);
58
    }
59
60 1
    public function findOne(string $space, $params = []) : ?Entity
61
    {
62 1
        return $this->get(Mapper::class)->findOne($space, $params);
63
    }
64
65 1
    public function findOrFail(string $space, $params = []) : Entity
66
    {
67 1
        return $this->get(Mapper::class)->findOrFail($space, $params);
68
    }
69
70 1
    public function remove(string $space, array $params = [])
71
    {
72 1
        return $this->get(Mapper::class)->remove($space, $params);
73
    }
74
75
    public function __debugInfo()
76
    {
77
        $info = get_object_vars($this);
78
        unset($info['app']);
79
        return $info;
80
    }
81
}
82