Lines 100.00% 41 / 41
Methods 100.00% 4 / 4
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 fromLoginParameters 100.00% 9 / 9 100.00% 1 / 1 1
 fromAdditionalParameters 100.00% 18 / 18 100.00% 1 / 1 5
 fromQuickLogin 100.00% 6 / 6 100.00% 1 / 1 1
 writeWorkstationUpdate 100.00% 8 / 8 100.00% 1 / 1 2
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($data, \BO\Zmsentities\Workstation $workstation): bool
87    {
88        $formData = $data->getValues();
89        $workstation->setValidatedName($formData);
90        $workstation->setValidatedHint($formData);
91        $workstation->setValidatedScope($formData);
92        $workstation->setValidatedAppointmentsOnly($formData);
93        unset($workstation->useraccount['departments']);
94        $result = \App::$http->readPostResult('/workstation/', $workstation)->getEntity();
95        return ($result) ? true : false;
96    }
97}