Test Failed
Push — master ( f562c0...ed7d3a )
by Dominik
02:11
created

Course   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 175
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 175
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 1

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A create() 0 7 1
A fromPersistence() 0 11 1
A toPersistence() 0 10 1
A getId() 0 4 1
A getName() 0 4 1
A setName() 0 6 1
A getLevel() 0 4 1
A setLevel() 0 6 1
A getProgress() 0 4 1
A setProgress() 0 6 1
A isActive() 0 4 1
A setActive() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\ApiSkeleton\Model;
6
7
use Chubbyphp\Model\ModelInterface;
8
use Ramsey\Uuid\Uuid;
9
10
final class Course implements ModelInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    private $id;
16
17
    /**
18
     * @var string
19
     */
20
    private $name;
21
22
    /**
23
     * @var int
24
     */
25
    private $level;
26
27
    const LEVEL_START = 1;
28
    const LEVEL_MEDIUM = 2;
29
    const LEVEL_ADVANCED = 3;
30
    const LEVEL_EXPERT = 4;
31
32
    const LEVEL = [
33
        self::LEVEL_START,
34
        self::LEVEL_MEDIUM,
35
        self::LEVEL_ADVANCED,
36
        self::LEVEL_EXPERT,
37
    ];
38
39
    /**
40
     * @var float
41
     */
42
    private $progress;
43
44
    /**
45
     * @var bool
46
     */
47
    private $active;
48
49
    private function __construct()
50
    {
51
    }
52
53
    /**
54
     * @param string|null $id
55
     *
56
     * @return self
57
     */
58
    public static function create(string $id = null): self
59
    {
60
        $self = new self();
61
        $self->id = $id ?? (string) Uuid::uuid4();
62
63
        return $self;
64
    }
65
66
    /**
67
     * @param array $data
68
     *
69
     * @return self|ModelInterface
70
     */
71
    public static function fromPersistence(array $data): ModelInterface
72
    {
73
        $self = new self();
74
        $self->id = $data['id'];
75
        $self->name = $data['name'];
76
        $self->level = (int) $data['level'];
77
        $self->progress = (float) $data['progress'];
78
        $self->active = (bool) $data['active'];
79
80
        return $self;
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    public function toPersistence(): array
87
    {
88
        return [
89
            'id' => $this->id,
90
            'name' => $this->name,
91
            'level' => $this->level,
92
            'progress' => $this->progress,
93
            'active' => $this->active,
94
        ];
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getId(): string
101
    {
102
        return $this->id;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getName(): string
109
    {
110
        return $this->name;
111
    }
112
113
    /**
114
     * @param string $name
115
     *
116
     * @return self
117
     */
118
    public function setName(string $name): self
119
    {
120
        $this->name = $name;
121
122
        return $this;
123
    }
124
125
    /**
126
     * @return int
127
     */
128
    public function getLevel(): int
129
    {
130
        return $this->level;
131
    }
132
133
    /**
134
     * @param int $level
135
     *
136
     * @return self
137
     */
138
    public function setLevel(int $level): self
139
    {
140
        $this->level = $level;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @return float
147
     */
148
    public function getProgress(): float
149
    {
150
        return $this->progress;
151
    }
152
153
    /**
154
     * @param float $progress
155
     *
156
     * @return self
157
     */
158
    public function setProgress(float $progress): self
159
    {
160
        $this->progress = $progress;
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function isActive(): bool
169
    {
170
        return $this->active;
171
    }
172
173
    /**
174
     * @param bool $active
175
     *
176
     * @return self
177
     */
178
    public function setActive(bool $active): self
179
    {
180
        $this->active = $active;
181
182
        return $this;
183
    }
184
}
185