Extras::hasExtra()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Extras information
4
 * User: moyo
5
 * Date: 12/12/2017
6
 * Time: 12:05 PM
7
 */
8
9
namespace Carno\RPC\Chips\Protocol;
10
11
use Closure;
12
13
trait Extras
14
{
15
    /**
16
     * @var array
17
     */
18
    private $extras = [];
19
20
    /**
21
     * @param string $key
22
     * @return bool
23
     */
24
    public function hasExtra(string $key) : bool
25
    {
26
        return isset($this->extras[$key]);
27
    }
28
29
    /**
30
     * @param string $key
31
     * @return mixed
32
     */
33
    public function getExtra(string $key)
34
    {
35
        return $this->extras[$key] ?? null;
36
    }
37
38
    /**
39
     * @param string $key
40
     * @param mixed $val
41
     * @return static
42
     */
43
    public function setExtra(string $key, $val) : self
44
    {
45
        $this->extras[$key] = $val;
46
        return $this;
47
    }
48
49
    /**
50
     * @param string $key
51
     * @param Closure $setter
52
     */
53
    public function opsExtra(string $key, Closure $setter) : void
54
    {
55
        isset($this->extras[$key]) || $this->extras[$key] = [];
56
        $setter($this->extras[$key]);
57
    }
58
}
59