Completed
Push — develop ( 7585df...411e92 )
by
unknown
22:06 queued 11:09
created

FactsFieldset::init()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 80
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 80
rs 8.8387
cc 1
eloc 55
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/**  */
11
namespace Applications\Form;
12
13
use Core\Form\DisableElementsCapableInterface;
14
use Zend\Form\Fieldset;
15
use Core\Form\EmptySummaryAwareInterface;
16
17
/**
18
 * Facts fieldset. Defines formular fields of the facts form fieldset.
19
 *
20
 * @author Mathias Gelhausen <[email protected]>
21
 */
22
class FactsFieldset extends Fieldset implements DisableElementsCapableInterface, EmptySummaryAwareInterface
23
{
24
    /**
25
     * The empty summary notice.
26
     *
27
     * @var string
28
     */
29
    protected $emptySummaryNotice = /*@translate*/ 'Click here to enter facts.';
30
31
    /**
32
     * Defines the Facts formular. All fields of the facts form are added by default. Fields,
33
     * which are disables by the users settings are removed
34
     */
35
    public function init()
36
    {
37
        $this->setHydrator(new \Core\Entity\Hydrator\EntityHydrator())
38
             ->setName('base');
39
40
        $this->add(
41
            array(
42
            'name' => 'willingnessToTravel',
43
            'type' => '\Zend\Form\Element\Select',
44
            'options' => array(
45
                'value_options' => array(
46
                    '' => '', // needed for jquery select2 to render the placeholder
47
                    "yes"=>/*@translate*/ "Yes",
48
                    "conditioned" => /*@translate*/ "conditioned",
49
                    "no"=>/*@translate*/ "No"),
50
                'label' => /*@translate*/ 'Willingness to travel',
51
                'description' => /*@translate*/ 'Enter your willingness to travel.',
52
                'disable_capable' => array(
53
                    'description' => /*@translate*/ 'Ask the applicant about the willingness to travel',
54
                ),
55
            ),
56
            'attributes' => array(
57
                'data-placeholder' => /*@translate*/ 'please select',
58
                'data-allowclear' => 'false',
59
                'data-searchbox' => -1,
60
            ),
61
            )
62
        );
63
64
        $this->add(
65
            array(
66
            'name' => 'earliestStartingDate',
67
            'type' => "date",
68
            'options' => array(
69
                'label' => /*@translate*/ 'Earliest starting date',
70
                'description' => /*@translate*/ 'Enter the earliest starting date.',
71
                'disable_capable' => array(
72
                    'description' => /*@translate*/ 'Ask the applicant about the earliest starting date.',
73
                ),
74
            ),
75
            )
76
        );
77
78
        $this->add(
79
            array(
80
                'name'    => 'expectedSalary',
81
                'options' => array(
82
                    'label'           => /*@translate*/ 'Expected salary',
83
                    'description'     => /*@translate*/ 'Your salary requirements should be the annual amount before taxes. Do not forget to provide the currency sign.',
84
                    'disable_capable' => array(
85
                        'description' => /*@translate*/ 'Ask users about their expected salary.',
86
                    ),
87
                ),
88
            )
89
        );
90
91
        $this->add(
92
            array(
93
                'name'       => 'drivingLicense',
94
                'type'       => '\Zend\Form\Element\Select',
95
                'options'    => array(
96
                    'value_options'   => array(
97
                        ''  => '', // needed for jquery select2 to render the placeholder
98
                        "1" =>/*@translate*/ "Yes",
99
                        "0" =>/*@translate*/ "No"
100
                    ),
101
                    'label'           => /*@translate*/ 'driving license',
102
                    'description'     => /*@translate*/ 'Do you have a driving license?',
103
                    'disable_capable' => array(
104
                        'description' => /*@translate*/ 'Ask the applicant, if he has a driving license.',
105
                    ),
106
                ),
107
                'attributes' => [
108
                    'data-allowclear'  => 'false',
109
                    'data-searchbox'   => -1,
110
                    'data-placeholder' => /*@translate*/ 'please select',
111
                ]
112
            )
113
        );
114
    }
115
116
    /**
117
     * If all elements have empty values, the form will be displayed collapsed with the EmptySummaryNotice
118
     *
119
     * @return bool
120
     */
121
    public function isSummaryEmpty()
122
    {
123
        foreach ($this as $element) { /* @var $element \Zend\Form\ElementInterface */
124
            if ('' != $element->getValue()) {
125
                return false;
126
            }
127
        }
128
        return true;
129
    }
130
131
    /**
132
     * @param $message
133
     *
134
     * @return $this
135
     */
136
    public function setEmptySummaryNotice($message)
137
    {
138
        $this->emptySummaryNotice = $message;
139
        return $this;
140
    }
141
142
    /**
143
     * @return string
144
     */
145
    public function getEmptySummaryNotice()
146
    {
147
        return $this->emptySummaryNotice;
148
    }
149
150
    /**
151
     * @param bool $flag
152
     *
153
     * @return $this
154
     */
155
    public function setIsDisableCapable($flag)
156
    {
157
        $this->options['is_disable_capable'] = $flag;
158
159
        return $this;
160
    }
161
162
    /**
163
     * @return bool
164
     */
165
    public function isDisableCapable()
166
    {
167
        return isset($this->options['is_disable_capable'])
168
               ? $this->options['is_disable_capable'] : true;
169
    }
170
171
    /**
172
     * @param bool $flag
173
     *
174
     * @return $this
175
     */
176
    public function setIsDisableElementsCapable($flag)
177
    {
178
        $this->options['is_disable_elements_capable'] = $flag;
179
180
        return $this;
181
    }
182
183
    /**
184
     * @return bool
185
     */
186
    public function isDisableElementsCapable()
187
    {
188
        return isset($this->options['is_disable_elements_capable'])
189
            ? $this->options['is_disable_elements_capable']
190
            : true;
191
    }
192
193
    /**
194
     * Removes elements from Facts form.
195
     *
196
     * @param array $map
197
     * @return $this
198
     */
199
    public function disableElements(array $map)
200
    {
201
        foreach ($map as $element) {
202
            $this->remove($element);
203
        }
204
        return $this;
205
    }
206
}
207