Passed
Push — master ( 749b16...167cfa )
by Gabor
04:47
created

IndexAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 6
dl 0
loc 107
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTemplateName() 0 4 1
B getTemplateData() 0 89 1
1
<?php
2
/**
3
 * WebHemi.
4
 *
5
 * PHP version 7.1
6
 *
7
 * @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com)
8
 * @license   https://opensource.org/licenses/MIT The MIT License (MIT)
9
 *
10
 * @link      http://www.gixx-web.com
11
 */
12
declare(strict_types=1);
13
14
namespace WebHemi\Middleware\Action\Website;
15
16
use WebHemi\Form\Html\HtmlMultipleFormElement;
17
use WebHemi\Middleware\AbstractMiddlewareAction;
18
use WebHemi\Form\Html\HtmlForm;
19
use WebHemi\Form\Html\HtmlFormElement;
20
use WebHemi\Form\Html\Html5FormElement;
21
22
/**
23
 * Class IndexAction
24
 */
25
class IndexAction extends AbstractMiddlewareAction
26
{
27
    /**
28
     * Gets template map name or template file path.
29
     *
30
     * @return string
31
     */
32
    public function getTemplateName() : string
33
    {
34
        return 'website-index';
35
    }
36
37
    /**
38
     * Gets template data.
39
     *
40
     * @return array
41
     */
42
    public function getTemplateData() : array
43
    {
44
        // Test refactore Form elements
45
        $singleCheckbox = new HtmlFormElement(
46
            HtmlFormElement::HTML_ELEMENT_INPUT_CHECKBOX,
47
            'accept',
48
            'Accept terms of usage.',
49
            [true]
50
        );
51
52
        $multiCheckbox = new HtmlFormElement(
53
            HtmlFormElement::HTML_ELEMENT_INPUT_CHECKBOX,
54
            'my_locations',
55
            'I have already been...',
56
            ['uk', 'eu'],
57
            [
58
                'The United States' => 'us',
59
                'European Union' => 'eu',
60
                'United Kingdom' => 'uk'
61
            ]
62
        );
63
64
        $radioGroup = new HtmlFormElement(
65
            HtmlFormElement::HTML_ELEMENT_INPUT_RADIO,
66
            'curent_lang',
67
            'Current language',
68
            ['hu-HU'],
69
            [
70
                'English' => 'en-GB',
71
                'German' => 'de-DE',
72
                'Hungarian' => 'hu-HU'
73
            ]
74
        );
75
76
        $select = new HtmlMultipleFormElement(
77
            HtmlMultipleFormElement::HTML_ELEMENT_SELECT,
78
            'something',
79
            null,
80
            ['australia', 'india'],
81
            [
82
                'Default' => [
83
                    'Europe' => 'europe',
84
                    'America' => 'america',
85
                    'Australia' => 'australia'
86
                ],
87
                'Africa' => 'africa',
88
                'Asia' => 'asia',
89
                'Antarctica' => 'antarctica',
90
                'India' => 'india'
91
            ]
92
        );
93
        $select->setMultiple(true);
94
95
        $form = new HtmlForm('test', '', 'POST');
96
        $form->addElement(
97
                new HtmlFormElement(
98
                    HtmlFormElement::HTML_ELEMENT_INPUT_HIDDEN,
99
                    'csrf',
100
                    null,
101
                    [md5('something')]
102
                )
103
            )
104
            ->addElement(
105
                new HtmlFormElement(
106
                    HtmlFormElement::HTML_ELEMENT_INPUT_TEXT,
107
                    'name',
108
                    'Login name',
109
                    ['Joker']
110
                )
111
            )
112
            ->addElement(
113
                new HtmlFormElement(
114
                    HtmlFormElement::HTML_ELEMENT_INPUT_PASSWORD,
115
                    'password',
116
                    'Password'
117
                )
118
            )
119
            ->addElement($singleCheckbox)
120
            ->addElement($multiCheckbox)
121
            ->addElement($radioGroup)
122
            ->addElement($select)
123
            ->addElement(new Html5FormElement(Html5FormElement::HTML_ELEMENT_INPUT_NUMBER, 'num', 'Num',[4], [1, 16]))
124
            ->addElement(new Html5FormElement(Html5FormElement::HTML_ELEMENT_INPUT_RANGE, 'range', 'Range',[4], [1, 6, 0.2]))
125
            ->addElement(new HtmlFormElement(HtmlFormElement::HTML_ELEMENT_BUTTON, 'submit', 'Submit'));
126
127
        return [
128
            'form' => $form
129
        ];
130
    }
131
}
132