Completed
Push — master ( bdaaad...4f4372 )
by personal
04:35 queued 45s
created

Metrics::attach()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Hal\Metric;
3
4
/**
5
 * Class Metrics
6
 * @package Hal\Metric
7
 */
8
class Metrics implements \JsonSerializable
9
{
10
11
    /**
12
     * @var array
13
     */
14
    private $data = [];
15
16
    /**
17
     * @param $metric
18
     * @return $this
19
     */
20
    public function attach($metric)
21
    {
22
        $this->data[$metric->getName()] = $metric;
23
        return $this;
24
    }
25
26
    /**
27
     * @param $key
28
     * @return null
29
     */
30
    public function get($key)
31
    {
32
        return $this->has($key) ? $this->data[$key] : null;
33
    }
34
35
    /**
36
     * @param $key
37
     * @return bool
38
     */
39
    public function has($key)
40
    {
41
        return isset($this->data[$key]);
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function all()
48
    {
49
        return $this->data;
50
    }
51
52
    /**
53
     * @inheritdoc
54
     */
55
    function jsonSerialize()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
    {
57
        return $this->all();
58
    }
59
}