Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
81.91% |
77 / 94 |
|
94.12% |
32 / 34 |
CRAP | |
0.00% |
0 / 1 |
| Session | |
81.91% |
77 / 94 |
|
94.12% |
32 / 34 |
95.35 | |
0.00% |
0 / 1 |
| getDefaults | |
100.00% |
34 / 34 |
|
100.00% |
1 / 1 |
1 | |||
| getContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getBasket | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getHuman | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRequests | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getProviders | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getProcess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getScope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAuthKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLastStep | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| getStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| removeLastStep | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getSelectedDate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEntryData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEmpty | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
4 | |||
| isInChange | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isStalled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isReserved | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isConfirmed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isPreconfirmed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| isFinished | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| isProcessDeleted | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| hasStatus | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasProcess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasAuthKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasChangedProcess | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasPreviousAppointmentSearch | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasRequests | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasProvider | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasScope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasDate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| hasDifferentEntry | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
8 | |||
| withOidcDataOnly | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
72 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsentities; |
| 4 | |
| 5 | /** |
| 6 | * Extension for Twig and Slim |
| 7 | * |
| 8 | * Schema-backed entity (ArrayObject::ARRAY_AS_PROPS); document dynamic keys for Psalm. |
| 9 | * |
| 10 | * @property string $id |
| 11 | * @property string $name |
| 12 | * @property array $content |
| 13 | * |
| 14 | * @SuppressWarnings(PublicMethod) |
| 15 | * @SuppressWarnings(TooManyMethods) |
| 16 | * @SuppressWarnings(Complexity) |
| 17 | */ |
| 18 | class Session extends Schema\Entity |
| 19 | { |
| 20 | public const string PRIMARY = 'id'; |
| 21 | |
| 22 | public static $schema = "session.json"; |
| 23 | |
| 24 | /** |
| 25 | * @return ((int|int[]|string)[]|string)[][] |
| 26 | * |
| 27 | */ |
| 28 | #[\Override] |
| 29 | public function getDefaults() |
| 30 | { |
| 31 | return [ |
| 32 | 'content' => array( |
| 33 | 'basket' => [ |
| 34 | 'requests' => '', |
| 35 | 'providers' => '', |
| 36 | 'scope' => '0', |
| 37 | 'process' => '0', |
| 38 | 'date' => '0', |
| 39 | 'familyName' => '', |
| 40 | 'email' => '', |
| 41 | 'telephone' => '', |
| 42 | 'amendment' => '', |
| 43 | 'authKey' => '' |
| 44 | ], |
| 45 | 'human' => [ |
| 46 | 'captcha_text' => '', |
| 47 | 'client' => 0, |
| 48 | 'ts' => 0, |
| 49 | 'origin' => '', |
| 50 | 'remoteAddress' => '', |
| 51 | 'referer' => '', |
| 52 | 'step' => array( |
| 53 | 'dayselect' => 0, |
| 54 | 'timeselect' => 0, |
| 55 | 'register' => 0, |
| 56 | 'summary' => 0 |
| 57 | ) |
| 58 | ], |
| 59 | 'source' => 'dldb', |
| 60 | 'status' => 'start', |
| 61 | 'X-Authkey' => '', |
| 62 | 'error' => '' |
| 63 | ) |
| 64 | ]; |
| 65 | } |
| 66 | |
| 67 | public function getContent() |
| 68 | { |
| 69 | return $this->toProperty()->content->get(); |
| 70 | } |
| 71 | |
| 72 | public function getBasket() |
| 73 | { |
| 74 | return $this->toProperty()->content->basket->get(); |
| 75 | } |
| 76 | |
| 77 | public function getHuman() |
| 78 | { |
| 79 | return $this->toProperty()->content->human->get(); |
| 80 | } |
| 81 | |
| 82 | public function getRequests() |
| 83 | { |
| 84 | return Helper\Sorter::toSortedCsv($this->toProperty()->content->basket->requests->get()); |
| 85 | } |
| 86 | |
| 87 | public function getProviders() |
| 88 | { |
| 89 | return Helper\Sorter::toSortedCsv($this->toProperty()->content->basket->providers->get()); |
| 90 | } |
| 91 | |
| 92 | public function getProcess() |
| 93 | { |
| 94 | return $this->toProperty()->content->basket->process->get(); |
| 95 | } |
| 96 | |
| 97 | public function getSource() |
| 98 | { |
| 99 | return $this->toProperty()->content->source->get(); |
| 100 | } |
| 101 | |
| 102 | public function getScope() |
| 103 | { |
| 104 | return $this->toProperty()->content->basket->scope->get(); |
| 105 | } |
| 106 | |
| 107 | public function getAuthKey() |
| 108 | { |
| 109 | return $this->toProperty()->content->basket->authKey->get(); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return (int|string)|false|null |
| 114 | * |
| 115 | */ |
| 116 | public function getLastStep() |
| 117 | { |
| 118 | $steps = $this->toProperty()->content->human->step->get(); |
| 119 | $steps = (is_array($steps)) ? array_keys($steps) : null; |
| 120 | return (null !== $steps) ? end($steps) : $steps; |
| 121 | } |
| 122 | |
| 123 | public function getStatus() |
| 124 | { |
| 125 | return $this->toProperty()->content->status->get(); |
| 126 | } |
| 127 | |
| 128 | public function removeLastStep(): static |
| 129 | { |
| 130 | unset($this->content['human']['step'][$this->getLastStep()]); |
| 131 | return $this; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * |
| 136 | * Get selected date |
| 137 | * |
| 138 | * @return integer |
| 139 | */ |
| 140 | public function getSelectedDate() |
| 141 | { |
| 142 | return $this->toProperty()->content->basket->date->get(); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * |
| 147 | * Get entry data |
| 148 | * |
| 149 | * @return array |
| 150 | */ |
| 151 | public function getEntryData() |
| 152 | { |
| 153 | return $this->toProperty()->content->entry->get(); |
| 154 | } |
| 155 | |
| 156 | public function isEmpty(): bool |
| 157 | { |
| 158 | return (! $this->hasProvider() && ! $this->hasRequests() && ! $this->hasScope()) ? true : false; |
| 159 | } |
| 160 | |
| 161 | public function isInChange(): bool |
| 162 | { |
| 163 | return ('inChange' == $this->getStatus()) ? true : false; |
| 164 | } |
| 165 | |
| 166 | public function isStalled(): bool |
| 167 | { |
| 168 | return ('stalled' == $this->getStatus()) ? true : false; |
| 169 | } |
| 170 | |
| 171 | public function isReserved(): bool |
| 172 | { |
| 173 | return ('reserved' == $this->getStatus()) ? true : false; |
| 174 | } |
| 175 | |
| 176 | public function isConfirmed(): bool |
| 177 | { |
| 178 | return ('confirmed' == $this->getStatus()) ? true : false; |
| 179 | } |
| 180 | |
| 181 | public function isPreconfirmed(): bool |
| 182 | { |
| 183 | return ('preconfirmed' == $this->getStatus()) ? true : false; |
| 184 | } |
| 185 | |
| 186 | public function isFinished(): bool |
| 187 | { |
| 188 | return ('finished' == $this->getStatus()) ? true : false; |
| 189 | } |
| 190 | |
| 191 | public function isProcessDeleted(): bool |
| 192 | { |
| 193 | return ! $this->hasProcess(); |
| 194 | } |
| 195 | |
| 196 | public function hasStatus(): bool |
| 197 | { |
| 198 | return (null === $this->getStatus()) ? false : true; |
| 199 | } |
| 200 | |
| 201 | public function hasProcess(): bool |
| 202 | { |
| 203 | return (null === $this->getProcess()) ? false : true; |
| 204 | } |
| 205 | |
| 206 | public function hasAuthKey(): bool |
| 207 | { |
| 208 | return (null === $this->getAuthKey()) ? false : true; |
| 209 | } |
| 210 | |
| 211 | public function hasChangedProcess(): bool |
| 212 | { |
| 213 | return ('inChange' == $this->getStatus()) ? true : false; |
| 214 | } |
| 215 | |
| 216 | public function hasPreviousAppointmentSearch(): bool |
| 217 | { |
| 218 | return ('inProgress' == $this->getStatus()) ? true : false; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * Check if requests exists |
| 223 | * |
| 224 | * @return boolean |
| 225 | */ |
| 226 | public function hasRequests() |
| 227 | { |
| 228 | return ($this->getRequests()) ? true : false; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * |
| 233 | * Check if provider exists |
| 234 | * |
| 235 | * @return boolean |
| 236 | */ |
| 237 | public function hasProvider() |
| 238 | { |
| 239 | return ($this->getProviders()) ? true : false; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * |
| 244 | * Check if scope exists |
| 245 | * |
| 246 | * @return boolean |
| 247 | */ |
| 248 | public function hasScope() |
| 249 | { |
| 250 | return ($this->getScope()) ? true : false; |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * |
| 255 | * Check if date exists |
| 256 | * |
| 257 | * @return boolean |
| 258 | */ |
| 259 | public function hasDate() |
| 260 | { |
| 261 | return ($this->getSelectedDate()) ? true : false; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * |
| 266 | * Check if entry parameter are different |
| 267 | * |
| 268 | * @return boolean |
| 269 | */ |
| 270 | public function hasDifferentEntry($newEntryData) |
| 271 | { |
| 272 | return ( |
| 273 | ($this->getProviders() || $this->getScope()) && |
| 274 | $this->getRequests() && |
| 275 | $this->getEntryData() && |
| 276 | ( |
| 277 | !($this->getProviders() == Helper\Sorter::toSortedCsv($newEntryData['providers'])) || |
| 278 | !($this->getRequests() == Helper\Sorter::toSortedCsv($newEntryData['requests'])) || |
| 279 | !($this->getScope() == $newEntryData['scope']) |
| 280 | ) |
| 281 | ) ? true : false; |
| 282 | } |
| 283 | |
| 284 | public function withOidcDataOnly(): static |
| 285 | { |
| 286 | $entity = clone $this; |
| 287 | if ($entity->toProperty()->content->basket->isAvailable()) { |
| 288 | unset($entity->content['basket']); |
| 289 | } |
| 290 | if ($entity->toProperty()->content->human->isAvailable()) { |
| 291 | unset($entity->content['human']); |
| 292 | } |
| 293 | if ($entity->toProperty()->content->entry->isAvailable()) { |
| 294 | unset($entity->content['entry']); |
| 295 | } |
| 296 | if ($entity->toProperty()->content->source->isAvailable()) { |
| 297 | unset($entity->content['source']); |
| 298 | } |
| 299 | if ($entity->toProperty()->content->status->isAvailable()) { |
| 300 | unset($entity->content['status']); |
| 301 | } |
| 302 | if ($entity->toProperty()->content['X-Authkey']->isAvailable()) { |
| 303 | unset($entity->content['X-Authkey']); |
| 304 | } |
| 305 | if ($entity->toProperty()->content->error->isAvailable()) { |
| 306 | unset($entity->content['error']); |
| 307 | } |
| 308 | return $entity; |
| 309 | } |
| 310 | } |