Completed
Push — master ( 0e746d...7bde59 )
by Thomas
02:12
created

Operation::setIdx()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Gielfeldt\TransactionalPHP;
4
5
/**
6
 * Class Operation
7
 *
8
 * @package Gielfeldt\TransactionalPHP
9
 */
10
class Operation
11
{
12
    /**
13
     * @var string[]
14
     */
15
    protected $idx;
16
17
    /**
18
     * @var callable
19
     */
20
    protected $callback;
21
22
    /**
23
     * @var mixed
24
     */
25
    protected $value;
26
27
    /**
28
     * Set callback.
29
     *
30
     * @param callable $callback
31
     *   The callback.
32
     *
33
     * @return $this
34
     */
35
    public function setCallback(callable $callback)
36
    {
37
        $this->callback = $callback;
38
        return $this;
39
    }
40
41
    /**
42
     * Get callback.
43
     *
44
     * @return callable|null
45
     */
46
    public function getCallback()
47
    {
48
        return $this->callback;
49
    }
50
51
    /**
52
     * @param mixed $value
53
     *   The value to set.
54
     *
55
     * @return $this
56
     */
57
    public function setValue($value)
58
    {
59
        $this->value = $value;
60
        return $this;
61
    }
62
63
    /**
64
     * Get value.
65
     *
66
     * @return mixed
67
     */
68
    public function getValue()
69
    {
70
        return is_callable($this->value) ? call_user_func($this->value) : $this->value;
71
    }
72
73
    /**
74
     * @param Connection $connection
75
     *   The connection to use for this id.
76
     * @param string $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
     *   The id.
78
     *
79
     * @return $this
80
     */
81
    public function setIdx(Connection $connection, $idx)
82
    {
83
        $this->idx[$connection->connectionId()] = $idx;
84
        return $this;
85
    }
86
87
    /**
88
     * Get id.
89
     *
90
     * @param Connection $connection
91
     *   The connection to get id from.
92
     *
93
     * @return string|null
94
     */
95
    public function idx(Connection $connection)
96
    {
97
        $connectionId = $connection->connectionId();
98
        return isset($this->idx[$connectionId]) ? $this->idx[$connectionId] : null;
99
    }
100
101
    /**
102
     * Execute operation.
103
     *
104
     * @return mixed
105
     */
106
    public function execute()
107
    {
108
        return call_user_func($this->callback);
109
    }
110
}
111