Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.29% |
25 / 28 |
|
84.62% |
11 / 13 |
CRAP | |
0.00% |
0 / 1 |
| Value | |
89.29% |
25 / 28 |
|
84.62% |
11 / 13 |
17.36 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| setListUri | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getListUri | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUri | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUri | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getLabel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setLabel | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getDependencyUri | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasChanges | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOriginalUri | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasModifiedUri | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| jsonSerialize | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2020-2021 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * @author Sergei Mikhailov <sergei.mikhailov@taotesting.com> |
| 21 | */ |
| 22 | |
| 23 | declare(strict_types=1); |
| 24 | |
| 25 | namespace oat\tao\model\Lists\Business\Domain; |
| 26 | |
| 27 | use tao_helpers_Uri; |
| 28 | |
| 29 | class Value implements \JsonSerializable |
| 30 | { |
| 31 | /** @var string|int|null */ |
| 32 | private $id; |
| 33 | |
| 34 | /** @var string */ |
| 35 | private $uri; |
| 36 | |
| 37 | /** @var string */ |
| 38 | private $listUri; |
| 39 | |
| 40 | /** @var string */ |
| 41 | private $label; |
| 42 | |
| 43 | /** @var string|null */ |
| 44 | private $dependencyUri; |
| 45 | |
| 46 | /** @var string|null */ |
| 47 | private $originalUri; |
| 48 | |
| 49 | /** @var bool */ |
| 50 | private $hasChanges = false; |
| 51 | |
| 52 | public function __construct($id, string $uri, string $label, string $dependencyUri = null) |
| 53 | { |
| 54 | $this->id = $id; |
| 55 | $this->uri = $uri; |
| 56 | $this->label = $label; |
| 57 | $this->dependencyUri = $dependencyUri; |
| 58 | $this->originalUri = $id === null ? null : $uri; |
| 59 | } |
| 60 | |
| 61 | public function setListUri(string $listUri): self |
| 62 | { |
| 63 | $this->listUri = $listUri; |
| 64 | |
| 65 | return $this; |
| 66 | } |
| 67 | |
| 68 | public function getListUri(): string |
| 69 | { |
| 70 | return $this->listUri; |
| 71 | } |
| 72 | |
| 73 | public function getId() |
| 74 | { |
| 75 | return $this->id; |
| 76 | } |
| 77 | |
| 78 | public function getUri(): string |
| 79 | { |
| 80 | return $this->uri; |
| 81 | } |
| 82 | |
| 83 | public function setUri(string $uri): self |
| 84 | { |
| 85 | if ($this->uri !== $uri) { |
| 86 | $this->hasChanges = true; |
| 87 | } |
| 88 | |
| 89 | $this->uri = $uri; |
| 90 | |
| 91 | return $this; |
| 92 | } |
| 93 | |
| 94 | public function getLabel(): string |
| 95 | { |
| 96 | return $this->label; |
| 97 | } |
| 98 | |
| 99 | public function setLabel(string $label): self |
| 100 | { |
| 101 | if ($this->label !== $label) { |
| 102 | $this->hasChanges = true; |
| 103 | } |
| 104 | |
| 105 | $this->label = $label; |
| 106 | |
| 107 | return $this; |
| 108 | } |
| 109 | |
| 110 | public function getDependencyUri(): ?string |
| 111 | { |
| 112 | return $this->dependencyUri; |
| 113 | } |
| 114 | |
| 115 | public function hasChanges(): bool |
| 116 | { |
| 117 | return $this->hasChanges; |
| 118 | } |
| 119 | |
| 120 | public function getOriginalUri(): ?string |
| 121 | { |
| 122 | return $this->originalUri; |
| 123 | } |
| 124 | |
| 125 | public function hasModifiedUri(): bool |
| 126 | { |
| 127 | return $this->uri && $this->originalUri !== $this->uri; |
| 128 | } |
| 129 | |
| 130 | public function jsonSerialize(): array |
| 131 | { |
| 132 | return [ |
| 133 | 'uri' => tao_helpers_Uri::encode($this->uri), |
| 134 | 'label' => $this->label, |
| 135 | 'dependencyUri' => tao_helpers_Uri::encode($this->dependencyUri), |
| 136 | ]; |
| 137 | } |
| 138 | } |