Passed
Push — master ( 53e7cc...f5cb33 )
by Romain
59s
created

Data   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 141
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A __construct() 0 11 1
A getPeriod() 0 4 1
A getValues() 0 4 1
A setValues() 0 10 4
A getTitle() 0 4 1
A getDescription() 0 4 1
A getId() 0 4 1
A getTag() 0 4 1
A create() 0 4 1
1
<?php
2
3
namespace Kerox\Messenger\Model;
4
5
use Kerox\Messenger\Model\Data\Value;
6
7
class Data
8
{
9
    /**
10
     * @var null|string
11
     */
12
    protected $name;
13
14
    /**
15
     * @var null|string
16
     */
17
    protected $period;
18
19
    /**
20
     * @var array
21
     */
22
    protected $values = [];
23
24
    /**
25
     * @var null|string
26
     */
27
    protected $title;
28
29
    /**
30
     * @var null|string
31
     */
32
    protected $description;
33
34
    /**
35
     * @var null|string
36
     */
37
    protected $id;
38
39
    /**
40
     * @var null|srting
41
     */
42
    protected $tag;
43
44
    /**
45
     * @var array
46
     */
47
    protected $data;
48
49
    /**
50
     * Data constructor.
51
     *
52
     * @param array $data
53
     */
54 5
    public function __construct(array $data)
55
    {
56 5
        $this->name = $data['name'] ?? null;
57 5
        $this->period = $data['period'] ?? null;
58 5
        $this->title = $data['title'] ?? null;
59 5
        $this->description = $data['description'] ?? null;
60 5
        $this->id = $data['id'] ?? null;
61 5
        $this->tag = $data['tag'] ?? null;
62
63 5
        $this->setValues($data);
64 5
    }
65
66
    /**
67
     * @return null|string
68
     */
69 1
    public function getName()
70
    {
71 1
        return $this->name;
72
    }
73
74
    /**
75
     * @return null|string
76
     */
77 1
    public function getPeriod()
78
    {
79 1
        return $this->period;
80
    }
81
82
    /**
83
     * @return \Kerox\Messenger\Model\Data\Value[]
84
     */
85 1
    public function getValues(): array
86
    {
87 1
        return $this->values;
88
    }
89
90
    /**
91
     * @param array $data
92
     *
93
     * @return \Kerox\Messenger\Model\Data
94
     */
95 5
    public function setValues(array $data): Data
96
    {
97 5
        if (isset($data['values']) && !empty($data['values'])) {
98 4
            foreach ($data['values'] as $value) {
99 4
                $this->values[] = new Value($value['value'], $value['end_time']);
100
            }
101
        }
102
103 5
        return $this;
104
    }
105
106
    /**
107
     * @return null|string
108
     */
109 1
    public function getTitle(): string
110
    {
111 1
        return $this->title;
112
    }
113
114
    /**
115
     * @return null|string
116
     */
117 1
    public function getDescription(): string
118
    {
119 1
        return $this->description;
120
    }
121
122
    /**
123
     * @return null|string
124
     */
125 1
    public function getId(): string
126
    {
127 1
        return $this->id;
128
    }
129
130
    /**
131
     * @return null|string
132
     */
133 1
    public function getTag(): string
134
    {
135 1
        return $this->tag;
136
    }
137
138
    /**
139
     * @param array $data
140
     *
141
     * @return \Kerox\Messenger\Model\Data
142
     */
143 4
    public static function create(array $data): Data
144
    {
145 4
        return new static($data);
146
    }
147
}
148