Lines 44.18% 19 / 43
Methods 25.00% 1 / 4
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 fromLoginParameters 0.00% 0 / 9 0.00% 0 / 1 2
 fromAdditionalParameters 50.00% 9 / 18 0.00% 0 / 1 8.12
 fromQuickLogin 0.00% 0 / 6 0.00% 0 / 1 2
 writeWorkstationUpdate 100.00% 10 / 10 100.00% 1 / 1 3
15class LoginForm
16{
17    /**
18     * form data for reuse in multiple controllers
19     */
20    public static function fromLoginParameters(): Collection
21    {
22        $collection = array();
23        // loginName
24        $collection['loginName'] = Validator::param('loginName')->isString()
25            ->isBiggerThan(2, "Es muss ein aussagekräftiger Name eingegeben werden")
26            ->isSmallerThan(40, "Der Name sollte 40 Zeichen nicht überschreiten");
27
28        // password
29        $collection['password'] = Validator::param('password')->isString()
30            ->isBiggerThan(2, "Es muss ein Passwort eingegeben werden")
31            ->isSmallerThan(20, "Das Passwort sollte 20 Zeichen nicht überschreiten");
32
33        // return validated collection
34        $collection = Validator::collection($collection);
35        return $collection;
36    }
37
38    /**
39     * form data for reuse in multiple controllers
40     */
41    public static function fromAdditionalParameters(): Collection
42    {
43        $collection = array();
44
45        // scope
46        if ('cluster' == Validator::param('scope')->isString()->getValue()) {
47            $collection['scope'] = Validator::param('scope')
48                ->isString('Bitte wählen Sie einen Standort aus');
49        } else {
50            $collection['scope'] = Validator::param('scope')
51                ->isNumber('Bitte wählen Sie einen Standort aus');
52        }
53
54        if (! Validator::param('appointmentsOnly')->isDeclared()->hasFailed()) {
55            $collection['appointmentsOnly'] = Validator::param('appointmentsOnly')
56                ->isNumber();
57        }
58
59        // workstation
60        if (! Validator::param('workstation')->isDeclared()->hasFailed()) {
61            $collection['workstation'] = Validator::param('workstation')
62                 ->isString('Bitte wählen Sie einen Arbeitsplatz oder den Tresen aus')
63                 ->isSmallerThan(8, "Die Arbeitsplatz-Bezeichnung sollte 8 Zeichen nicht überschreiten");
64        }
65        // hint
66        if (! Validator::param('hint')->isDeclared()->hasFailed()) {
67            $collection['hint'] = Validator::param('hint')
68                ->isString();
69        }
70
71        // return validated collection
72        $collection = Validator::collection($collection);
73        return $collection;
74    }
75
76    public static function fromQuickLogin(): Collection
77    {
78        $loginData = static::fromLoginParameters();
79        $additionalData = static::fromAdditionalParameters();
80        $collection = array_merge($loginData->getValues(), $additionalData->getValues());
81        $collection['redirectUrl'] = Validator::param('url')->isString();
82        $collection = Validator::collection($collection);
83        return $collection;
84    }
85
86    public static function writeWorkstationUpdate(mixed $data, mixed $workstation): bool
87    {
88        $result = false;
89        if (isset($workstation->useraccount)) {
90            $formData = $data->getValues();
91            $workstation->setValidatedName($formData);
92            $workstation->setValidatedHint($formData);
93            $workstation->setValidatedScope($formData);
94            $workstation->setValidatedAppointmentsOnly($formData);
95            unset($workstation->useraccount['departments']);
96            $result = \App::http()->readPostResult('/workstation/', $workstation)->getEntity();
97        }
98        return ($result) ? true : false;
99    }
100}