Row   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 66
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A fill() 0 6 2
A getLabel() 0 4 1
A getEvents() 0 4 1
A addEvent() 0 8 2
1
<?php
2
3
namespace Spiral\Statistics\Extract\Events;
4
5
use Spiral\Statistics\Exceptions\InvalidExtractEventException;
6
7
class Row
8
{
9
    /** @var string */
10
    private $label;
11
12
    /** @var array */
13
    private $events;
14
15
    /** @var array */
16
    private $records = [];
17
18
    /**
19
     * Row constructor.
20
     *
21
     * @param string $label
22
     * @param array  $events
23
     */
24
    public function __construct(string $label, array $events)
25
    {
26
        $this->label = $label;
27
        $this->events = $events;
28
29
        $this->fill();
30
    }
31
32
    /**
33
     * Fill blank data.
34
     */
35
    private function fill()
36
    {
37
        foreach ($this->events as $event) {
38
            $this->records[$event] = 0;
39
        }
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getLabel(): string
46
    {
47
        return $this->label;
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getEvents(): array
54
    {
55
        return $this->records;
56
    }
57
58
    /**
59
     * Add value to event.
60
     *
61
     * @param string $event
62
     * @param float  $value
63
     */
64
    public function addEvent(string $event, float $value)
65
    {
66
        if (!isset($this->records[$event])) {
67
            throw new InvalidExtractEventException($event);
68
        }
69
70
        $this->records[$event] += $value;
71
    }
72
}