Lines 86.17% 187 / 217
Methods 86.56% 58 / 67
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 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% 4 / 4 100.00% 1 / 1 3
 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
 [BO\Zmsentities\Schema\Entity] __construct 100.00% 4 / 4 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] exchangeArray 100.00% 4 / 4 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] offsetSet 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] getUnflattenedArray 100.00% 5 / 5 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] getValidator 100.00% 6 / 6 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] isValid 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] testValid 100.00% 7 / 7 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] createExample 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] getExample 100.00% 5 / 5 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] readJsonSchema 66.66% 6 / 9 0.00% 0 / 1 3.33
 [BO\Zmsentities\Schema\Entity] getEntityName 100.00% 4 / 4 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] setJsonCompressLevel 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] jsonSerialize 100.00% 11 / 11 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] __toString 100.00% 2 / 2 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] __get 0.00% 0 / 1 0.00% 0 / 1 2
 [BO\Zmsentities\Schema\Entity] __isset 0.00% 0 / 1 0.00% 0 / 1 2
 [BO\Zmsentities\Schema\Entity] __set 0.00% 0 / 1 0.00% 0 / 1 2
 [BO\Zmsentities\Schema\Entity] __unset 0.00% 0 / 1 0.00% 0 / 1 2
 [BO\Zmsentities\Schema\Entity] __clone 100.00% 3 / 3 100.00% 1 / 1 3
 [BO\Zmsentities\Schema\Entity] addData 100.00% 14 / 14 100.00% 1 / 1 6
 [BO\Zmsentities\Schema\Entity] withData 0.00% 0 / 3 0.00% 0 / 1 2
 [BO\Zmsentities\Schema\Entity] hasId 100.00% 1 / 1 100.00% 1 / 1 2
 [BO\Zmsentities\Schema\Entity] getId 100.00% 2 / 2 100.00% 1 / 1 3
 [BO\Zmsentities\Schema\Entity] toProperty 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] hasProperty 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] getProperty 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] withProperty 0.00% 0 / 3 0.00% 0 / 1 2
 [BO\Zmsentities\Schema\Entity] withLessData 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] withCleanedUpFormData 100.00% 6 / 6 100.00% 1 / 1 3
 [BO\Zmsentities\Schema\Entity] getResolveLevel 100.00% 1 / 1 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] setResolveLevel 100.00% 2 / 2 100.00% 1 / 1 1
 [BO\Zmsentities\Schema\Entity] withResolveLevel 100.00% 9 / 9 100.00% 1 / 1 5
 [BO\Zmsentities\Schema\Entity] withReference 100.00% 5 / 5 100.00% 1 / 1 2
18class 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(): mixed
68    {
69        return $this->toProperty()->content->get();
70    }
71
72    public function getBasket(): mixed
73    {
74        return $this->toProperty()->content->basket->get();
75    }
76
77    public function getHuman(): mixed
78    {
79        return $this->toProperty()->content->human->get();
80    }
81
82    public function getRequests(): string
83    {
84        return Helper\Sorter::toSortedCsv($this->toProperty()->content->basket->requests->get());
85    }
86
87    public function getProviders(): string
88    {
89        return Helper\Sorter::toSortedCsv($this->toProperty()->content->basket->providers->get());
90    }
91
92    public function getProcess(): mixed
93    {
94        return $this->toProperty()->content->basket->process->get();
95    }
96
97    public function getSource(): mixed
98    {
99        return $this->toProperty()->content->source->get();
100    }
101
102    public function getScope(): mixed
103    {
104        return $this->toProperty()->content->basket->scope->get();
105    }
106
107    public function getAuthKey(): mixed
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(): mixed
124    {
125        return $this->toProperty()->content->status->get();
126    }
127
128    public function removeLastStep(): static
129    {
130        $lastStep = $this->getLastStep();
131        if ($lastStep !== null && $lastStep !== false) {
132            unset($this->content['human']['step'][$lastStep]);
133        }
134        return $this;
135    }
136
137    /**
138     *
139     * Get selected date
140     *
141     * @return integer
142     */
143    public function getSelectedDate()
144    {
145        return $this->toProperty()->content->basket->date->get();
146    }
147
148    /**
149     *
150     * Get entry data
151     *
152     * @return array
153     */
154    public function getEntryData()
155    {
156        return $this->toProperty()->content->entry->get();
157    }
158
159    public function isEmpty(): bool
160    {
161        return (! $this->hasProvider() && ! $this->hasRequests() && ! $this->hasScope()) ? true : false;
162    }
163
164    public function isInChange(): bool
165    {
166        return ('inChange' == $this->getStatus()) ? true : false;
167    }
168
169    public function isStalled(): bool
170    {
171        return ('stalled' == $this->getStatus()) ? true : false;
172    }
173
174    public function isReserved(): bool
175    {
176        return ('reserved' == $this->getStatus()) ? true : false;
177    }
178
179    public function isConfirmed(): bool
180    {
181        return ('confirmed' == $this->getStatus()) ? true : false;
182    }
183
184    public function isPreconfirmed(): bool
185    {
186        return ('preconfirmed' == $this->getStatus()) ? true : false;
187    }
188
189    public function isFinished(): bool
190    {
191        return ('finished' == $this->getStatus()) ? true : false;
192    }
193
194    public function isProcessDeleted(): bool
195    {
196        return ! $this->hasProcess();
197    }
198
199    public function hasStatus(): bool
200    {
201        return (null === $this->getStatus()) ? false : true;
202    }
203
204    public function hasProcess(): bool
205    {
206        return (null === $this->getProcess()) ? false : true;
207    }
208
209    public function hasAuthKey(): bool
210    {
211        return (null === $this->getAuthKey()) ? false : true;
212    }
213
214    public function hasChangedProcess(): bool
215    {
216        return ('inChange' == $this->getStatus()) ? true : false;
217    }
218
219    public function hasPreviousAppointmentSearch(): bool
220    {
221        return ('inProgress' == $this->getStatus()) ? true : false;
222    }
223
224    /**
225     * Check if requests exists
226     *
227     * @return boolean
228     */
229    public function hasRequests()
230    {
231        return ($this->getRequests()) ? true : false;
232    }
233
234    /**
235     *
236     * Check if provider exists
237     *
238     * @return boolean
239     */
240    public function hasProvider()
241    {
242        return ($this->getProviders()) ? true : false;
243    }
244
245    /**
246     *
247     * Check if scope exists
248     *
249     * @return boolean
250     */
251    public function hasScope()
252    {
253        return ($this->getScope()) ? true : false;
254    }
255
256    /**
257     *
258     * Check if date exists
259     *
260     * @return boolean
261     */
262    public function hasDate()
263    {
264        return ($this->getSelectedDate()) ? true : false;
265    }
266
267    /**
268     *
269     * Check if entry parameter are different
270     *
271     * @return boolean
272     */
273    public function hasDifferentEntry(mixed $newEntryData)
274    {
275        return (
276            ($this->getProviders() || $this->getScope()) &&
277            $this->getRequests() &&
278            $this->getEntryData() &&
279            (
280                !($this->getProviders() == Helper\Sorter::toSortedCsv($newEntryData['providers'])) ||
281                !($this->getRequests() == Helper\Sorter::toSortedCsv($newEntryData['requests'])) ||
282                !($this->getScope() == $newEntryData['scope'])
283            )
284         ) ? true : false;
285    }
286
287    public function withOidcDataOnly(): static
288    {
289        $entity = clone $this;
290        if ($entity->toProperty()->content->basket->isAvailable()) {
291            unset($entity->content['basket']);
292        }
293        if ($entity->toProperty()->content->human->isAvailable()) {
294            unset($entity->content['human']);
295        }
296        if ($entity->toProperty()->content->entry->isAvailable()) {
297            unset($entity->content['entry']);
298        }
299        if ($entity->toProperty()->content->source->isAvailable()) {
300            unset($entity->content['source']);
301        }
302        if ($entity->toProperty()->content->status->isAvailable()) {
303            unset($entity->content['status']);
304        }
305        if ($entity->toProperty()->content['X-Authkey']->isAvailable()) {
306            unset($entity->content['X-Authkey']);
307        }
308        if ($entity->toProperty()->content->error->isAvailable()) {
309            unset($entity->content['error']);
310        }
311        return $entity;
312    }
313}

Inherited from BO\Zmsentities\Schema\Entity

59    public function __construct(mixed $input = null, int $flags = \ArrayObject::ARRAY_AS_PROPS, string $iterator_class = "ArrayIterator")
60    {
61        /** @var class-string<\ArrayIterator> $iterator_class */
62        parent::__construct($this->getDefaults(), $flags, $iterator_class);
63        if ($input) {
64            $input = $this->getUnflattenedArray($input);
65            $this->addData($input);
66        }
67    }
70    public function exchangeArray(object|array $input): array
71    {
72        parent::exchangeArray($this->getDefaults());
73        $input = $this->getUnflattenedArray($input);
74        $this->addData($input);
75        return $this->getArrayCopy();
76    }
82    public function offsetSet(mixed $key, mixed $value): void
83    {
84        /** @psalm-suppress PossiblyNullArgument */
85        parent::offsetSet($key, $value);
86    }
88    public function getUnflattenedArray(mixed $input): mixed
89    {
90        if (!$input instanceof UnflattedArray) {
91            $input = new UnflattedArray($input);
92            $input->getUnflattenedArray();
93        }
94        $input = $input->getValue();
95        return $input;
96    }
112    public function getValidator(string $locale = 'de_DE', int $resolveLevel = 0): Validator
113    {
114        $jsonSchema = self::readJsonSchema()->withResolvedReferences($resolveLevel);
115        $data = (new Schema($this))->withoutRefs();
116        if (Property::__keyExists('$schema', $data)) {
117            unset($data['$schema']);
118        }
119        $validator = new Validator($data->toJsonObject(true), $jsonSchema, $locale);
120        return $validator;
121    }
128    public function isValid(int $resolveLevel = 0): bool
129    {
130        $validator = $this->getValidator('de_DE', $resolveLevel = 0);
131        return $validator->isValid();
132    }
140    public function testValid(string $locale = 'de_DE', int $resolveLevel = 0): bool
141    {
142        $validator = $this->getValidator($locale, $resolveLevel);
143        if (!$validator->isValid()) {
144            $exception = new \BO\Zmsentities\Exception\SchemaValidation();
145            $exception->setSchemaName($this->getEntityName());
146            $exception->setValidationError($validator->getErrors());
147            throw $exception;
148        }
149        return true;
150    }
157    public static function createExample()
158    {
159        $object = new static();
160        return $object->getExample();
161    }
168    public static function getExample()
169    {
170        $class = get_called_class();
171        $jsonSchema = self::readJsonSchema();
172        if ($jsonSchema->offsetExists('example')) {
173            return new $class($jsonSchema['example']);
174        }
175        return new $class();
176    }
178    protected static function readJsonSchema(): mixed
179    {
180        $class = get_called_class();
181        if (!array_key_exists($class, self::$schemaCache)) {
182            $schemaFile = $class::$schema;
183            if (!is_string($schemaFile)) {
184                throw new \BO\Zmsentities\Exception\SchemaMissingJsonFile(
185                    'Missing JSON-Schema file for ' . $class
186                );
187            }
188            self::$schemaCache[$class] = Loader::asArray($schemaFile);
189        }
190        return self::$schemaCache[$class];
191    }
193    public function getEntityName(): string
194    {
195        $entity = get_class($this);
196        $entity = preg_replace('#.*[\\\]#', '', $entity) ?? '';
197        $entity = strtolower($entity);
198        return $entity;
199    }
201    public function setJsonCompressLevel(mixed $jsonCompressLevel): static
202    {
203        $this->jsonCompressLevel = $jsonCompressLevel;
204        return $this;
205    }
208    public function jsonSerialize(): mixed
209    {
210        $schema = array(
211            '$schema' => 'https://schema.berlin.de/queuemanagement/' . $this->getEntityName() . '.json'
212        );
213        $schema = array_merge($schema, $this->getArrayCopy());
214        if ($this instanceof \BO\Zmsentities\Helper\NoSanitize) {
215            $serialize = $schema;
216        } else {
217            $schema = new Schema($schema);
218            $schema->setDefaults($this->getDefaults());
219            $schema->setJsonCompressLevel($this->jsonCompressLevel);
220            $serialize = $schema->toJsonObject();
221        }
222        return $serialize;
223    }
225    public function __toString()
226    {
227        $encoded = json_encode($this->jsonSerialize(), JSON_HEX_QUOT);
228        return $encoded !== false ? $encoded : '';
229    }
235    public function __get(string $name): mixed
236    {
237        return $this->offsetGet($name);
238    }
240    public function __isset(string $name): bool
241    {
242        return $this->offsetExists($name);
243    }
245    public function __set(string $name, mixed $value): void
246    {
247        $this->offsetSet($name, $value);
248    }
250    public function __unset(string $name): void
251    {
252        $this->offsetUnset($name);
253    }
255    public function __clone()
256    {
257        foreach ($this as $key => $property) {
258            if (is_object($property)) {
259                $this[$key] = clone $property;
260            }
261        }
262    }
268    public function addData(array|object $mergeData): static
269    {
270        foreach ($mergeData as $key => $item) {
271            if (isset($this[$key])) {
272                if ($this[$key] instanceof Entity) {
273                    $this[$key]->setResolveLevel(($this->getResolveLevel() ?? 0) - 1);
274                    $this[$key]->addData($item);
275                } elseif ($this[$key] instanceof \BO\Zmsentities\Collection\Base) {
276                    $this[$key]->exchangeArray([]);
277                    $this[$key]->setResolveLevel(($this->getResolveLevel() ?? 0) - 1);
278                    $this[$key]->addData($item);
279                } elseif (is_array($this[$key])) {
280                    $this[$key] = array_replace_recursive($this[$key], $item);
281                } else {
282                    $this[$key] = $item;
283                }
284            } else {
285                $this[$key] = $item;
286            }
287        }
288        return $this;
289    }
294    public function withData(mixed $mergeData): static
295    {
296        $entity = clone $this;
297        $entity->addData($mergeData);
298        return $entity;
299    }
301    public function hasId(): bool
302    {
303        return (false !== $this->getId()) ? true : false;
304    }
306    public function getId(): mixed
307    {
308        $idName = $this::PRIMARY;
309        return ($this->offsetExists($idName) && $this[$idName]) ? $this[$idName] : false;
310    }
317    public function toProperty()
318    {
319        return new \BO\Zmsentities\Helper\Property($this);
320    }
322    public function hasProperty(mixed $propertyName): mixed
323    {
324        return $this->toProperty()->{$propertyName}->isAvailable();
325    }
327    public function getProperty(string $propertyName, mixed $default = ''): mixed
328    {
329        return $this->toProperty()->{$propertyName}->get($default);
330    }
335    public function withProperty(mixed $propertyName, mixed $newValue): static
336    {
337        $entity = clone $this;
338        $entity[$propertyName] = $newValue;
339        return $entity;
340    }
347    public function withLessData()
348    {
349        return clone $this;
350    }
357    public function withCleanedUpFormData()
358    {
359        $entity = clone $this;
360        if (isset($entity['save'])) {
361            unset($entity['save']);
362        }
363        if (isset($entity['removeImage'])) {
364            unset($entity['removeImage']);
365        }
366        return $entity;
367    }
372    public function getResolveLevel()
373    {
374        return $this->resolveLevel;
375    }
381    public function setResolveLevel($resolveLevel)
382    {
383        $this->resolveLevel = $resolveLevel;
384        return $this;
385    }
393    public function withResolveLevel($resolveLevel): self|array
394    {
395        if ($resolveLevel >= 0) {
396            $entity = clone $this;
397            foreach ($entity as $key => $value) {
398                if ($value instanceof Entity || $value instanceof \BO\Zmsentities\Collection\Base) {
399                    $entity[$key] = $value->withResolveLevel($resolveLevel - 1);
400                } else {
401                    $entity[$key] = $value;
402                }
403            }
404            $entity->setResolveLevel($resolveLevel);
405            return $entity;
406        } else {
407            return $this->withReference();
408        }
409    }
417    public function withReference($additionalData = []): self|array
418    {
419        if (isset($this[$this::PRIMARY])) {
420            $additionalData['$ref'] =
421                $this::$schemaRefPrefix . $this->getEntityName() . '/' . $this[$this::PRIMARY] . '/';
422            return $additionalData;
423        } else {
424            return $this->withResolveLevel(0);
425        }
426    }