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

Job::confirm()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 8
cp 0
rs 9.4285
cc 3
eloc 7
nc 2
nop 1
crap 12
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