Total Complexity | 7 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 78.56% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | trait HasCode |
||
12 | { |
||
13 | /** |
||
14 | * @var null|string |
||
15 | * |
||
16 | * @ORM\Column(type="string", length=30, nullable=true) |
||
17 | */ |
||
18 | private $code; |
||
19 | |||
20 | /** |
||
21 | * Set code |
||
22 | */ |
||
23 | 2 | public function setCode(?string $code): void |
|
24 | { |
||
25 | 2 | if ($code === '') { |
|
26 | $code = null; |
||
27 | } |
||
28 | |||
29 | 2 | if ($code !== $this->code && !$this->canUpdateCode()) { |
|
30 | throw new Exception('Only majors and administrators are allowed to update card.code'); |
||
31 | } |
||
32 | |||
33 | 2 | $this->code = $code; |
|
34 | 2 | } |
|
35 | |||
36 | /** |
||
37 | * Get code |
||
38 | */ |
||
39 | 7 | public function getCode(): ?string |
|
40 | { |
||
41 | 7 | return $this->code; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Simple ACL check |
||
46 | */ |
||
47 | 5 | private function canUpdateCode(): bool |
|
57 | } |
||
58 | } |
||
59 |