FormHelper   B
last analyzed

Complexity

Total Complexity 45

Size/Duplication

Total Lines 420
Duplicated Lines 4.29 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 18
loc 420
rs 8.3673
c 0
b 0
f 0
wmc 45
lcom 1
cbo 1

22 Methods

Rating   Name   Duplication   Size   Complexity  
A csrf() 0 4 1
A hidden() 0 4 1
B select() 0 22 6
A radios() 0 10 3
A radio() 0 4 2
A checkboxes() 0 10 3
A checkbox() 0 4 2
A label() 0 4 1
A textarea() 0 12 2
A file() 0 7 2
A input() 0 15 2
A text() 0 4 1
A password() 0 4 1
A email() 0 4 1
A number() 0 4 1
A numeric() 0 4 1
A date() 9 9 1
A datetime() 9 9 1
A errorClass() 0 4 2
A errorList() 0 16 3
A formValue() 0 8 3
B textEditor() 0 17 5

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like FormHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use FormHelper, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Helper;
13
14
use Jitamin\Foundation\Base;
15
16
/**
17
 * Form helpers.
18
 */
19
class FormHelper extends Base
20
{
21
    /**
22
     * Hidden CSRF token field.
23
     *
24
     * @return string
25
     */
26
    public function csrf()
27
    {
28
        return '<input type="hidden" name="csrf_token" value="'.$this->token->getCSRFToken().'"/>';
0 ignored issues
show
Documentation introduced by
The property token does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
29
    }
30
31
    /**
32
     * Display a hidden form field.
33
     *
34
     * @param string $name   Field name
35
     * @param array  $values Form values
36
     *
37
     * @return string
38
     */
39
    public function hidden($name, array $values = [])
40
    {
41
        return '<input type="hidden" name="'.$name.'" id="form-'.$name.'" '.$this->formValue($values, $name).'/>';
42
    }
43
44
    /**
45
     * Display a select field.
46
     *
47
     * @param string $name       Field name
48
     * @param array  $options    Options
49
     * @param array  $values     Form values
50
     * @param array  $errors     Form errors
51
     * @param array  $attributes
52
     * @param string $class      CSS class
53
     *
54
     * @return string
55
     */
56
    public function select($name, array $options, array $values = [], array $errors = [], array $attributes = [], $class = '')
57
    {
58
        $html = '<select name="'.$name.'" id="form-'.$name.'" class="'.$class.'" '.implode(' ', $attributes).'>';
59
60
        foreach ($options as $id => $value) {
61
            $html .= '<option value="'.$this->helper->text->e($id).'"';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
63
            if (isset($values->$name) && $id == $values->$name) {
64
                $html .= ' selected="selected"';
65
            }
66
            if (isset($values[$name]) && $id == $values[$name]) {
67
                $html .= ' selected="selected"';
68
            }
69
70
            $html .= '>'.$this->helper->text->e($value).'</option>';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
71
        }
72
73
        $html .= '</select>';
74
        $html .= $this->errorList($errors, $name);
75
76
        return $html;
77
    }
78
79
    /**
80
     * Display a radio field group.
81
     *
82
     * @param string $name    Field name
83
     * @param array  $options Options
84
     * @param array  $values  Form values
85
     *
86
     * @return string
87
     */
88
    public function radios($name, array $options, array $values = [])
89
    {
90
        $html = '';
91
92
        foreach ($options as $value => $label) {
93
            $html .= $this->radio($name, $label, $value, isset($values[$name]) && $values[$name] == $value);
94
        }
95
96
        return $html;
97
    }
98
99
    /**
100
     * Display a radio field.
101
     *
102
     * @param string $name     Field name
103
     * @param string $label    Form label
104
     * @param string $value    Form value
105
     * @param bool   $selected Field selected or not
106
     * @param string $class    CSS class
107
     *
108
     * @return string
109
     */
110
    public function radio($name, $label, $value, $selected = false, $class = '')
111
    {
112
        return '<label><input type="radio" name="'.$name.'" class="'.$class.'" value="'.$this->helper->text->e($value).'" '.($selected ? 'checked="checked"' : '').'> '.$this->helper->text->e($label).'</label>';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
113
    }
114
115
    /**
116
     * Display a checkboxes group.
117
     *
118
     * @param string $name    Field name
119
     * @param array  $options Options
120
     * @param array  $values  Form values
121
     *
122
     * @return string
123
     */
124
    public function checkboxes($name, array $options, array $values = [])
125
    {
126
        $html = '';
127
128
        foreach ($options as $value => $label) {
129
            $html .= $this->checkbox($name.'['.$value.']', $label, $value, isset($values[$name]) && in_array($value, $values[$name]));
130
        }
131
132
        return $html;
133
    }
134
135
    /**
136
     * Display a checkbox field.
137
     *
138
     * @param string $name    Field name
139
     * @param string $label   Form label
140
     * @param string $value   Form value
141
     * @param bool   $checked Field selected or not
142
     * @param string $class   CSS class
143
     *
144
     * @return string
145
     */
146
    public function checkbox($name, $label, $value, $checked = false, $class = '')
147
    {
148
        return '<label><input type="checkbox" name="'.$name.'" class="'.$class.'" value="'.$this->helper->text->e($value).'" '.($checked ? 'checked="checked"' : '').'>&nbsp;'.$this->helper->text->e($label).'</label>';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
149
    }
150
151
    /**
152
     * Display a form label.
153
     *
154
     * @param string $name       Field name
155
     * @param string $label      Form label
156
     * @param array  $attributes HTML attributes
157
     *
158
     * @return string
159
     */
160
    public function label($label, $name, array $attributes = [])
161
    {
162
        return '<label for="form-'.$name.'" '.implode(' ', $attributes).'>'.$this->helper->text->e($label).'</label>';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
163
    }
164
165
    /**
166
     * Display a textarea.
167
     *
168
     * @param string $name       Field name
169
     * @param array  $values     Form values
170
     * @param array  $errors     Form errors
171
     * @param array  $attributes HTML attributes
172
     * @param string $class      CSS class
173
     *
174
     * @return string
175
     */
176
    public function textarea($name, $values = [], array $errors = [], array $attributes = [], $class = '')
177
    {
178
        $class .= $this->errorClass($errors, $name);
179
180
        $html = '<textarea name="'.$name.'" id="form-'.$name.'" class="'.$class.'" ';
181
        $html .= implode(' ', $attributes).'>';
182
        $html .= isset($values[$name]) ? $this->helper->text->e($values[$name]) : '';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
183
        $html .= '</textarea>';
184
        $html .= $this->errorList($errors, $name);
185
186
        return $html;
187
    }
188
189
    /**
190
     * Display a markdown editor.
191
     *
192
     * @param string $name       Field name
193
     * @param array  $values     Form values
194
     * @param array  $errors     Form errors
195
     * @param array  $attributes
196
     *
197
     * @return string
198
     */
199
    public function textEditor($name, $values = [], array $errors = [], array $attributes = [])
200
    {
201
        $params = [
202
            'name'         => $name,
203
            'text'         => isset($values[$name]) ? $values[$name] : '',
204
            'css'          => $this->errorClass($errors, $name),
205
            'required'     => isset($attributes['required']) && $attributes['required'],
206
            'tabindex'     => isset($attributes['tabindex']) ? $attributes['tabindex'] : '-1',
207
            'labelPreview' => t('Preview'),
208
            'labelWrite'   => t('Write'),
209
            'placeholder'  => isset($attributes['placeholder']) ? $attributes['placeholder'] : t('Write your text in Markdown'),
210
        ];
211
        $html = '<div class="js-text-editor" data-params=\''.json_encode($params, JSON_HEX_APOS).'\'></div>';
212
        $html .= $this->errorList($errors, $name);
213
214
        return $html;
215
    }
216
217
    /**
218
     * Display file field.
219
     *
220
     * @param string $name
221
     * @param array  $errors
222
     * @param bool   $multiple
223
     *
224
     * @return string
225
     */
226
    public function file($name, array $errors = [], $multiple = false)
227
    {
228
        $html = '<input type="file" name="'.$name.'" id="form-'.$name.'" '.($multiple ? 'multiple' : '').'>';
229
        $html .= $this->errorList($errors, $name);
230
231
        return $html;
232
    }
233
234
    /**
235
     * Display a input field.
236
     *
237
     * @param string $type       HMTL input tag type
238
     * @param string $name       Field name
239
     * @param array  $values     Form values
240
     * @param array  $errors     Form errors
241
     * @param array  $attributes HTML attributes
242
     * @param string $class      CSS class
243
     *
244
     * @return string
245
     */
246
    public function input($type, $name, $values = [], array $errors = [], array $attributes = [], $class = '')
247
    {
248
        $class .= $this->errorClass($errors, $name);
249
250
        $html = '<input type="'.$type.'" name="'.$name.'" id="form-'.$name.'" '.$this->formValue($values, $name).' class="'.$class.'" ';
251
        $html .= implode(' ', $attributes).'>';
252
253
        if (in_array('required', $attributes)) {
254
            $html .= '<span class="form-required">*</span>';
255
        }
256
257
        $html .= $this->errorList($errors, $name);
258
259
        return $html;
260
    }
261
262
    /**
263
     * Display a text field.
264
     *
265
     * @param string $name       Field name
266
     * @param array  $values     Form values
267
     * @param array  $errors     Form errors
268
     * @param array  $attributes HTML attributes
269
     * @param string $class      CSS class
270
     *
271
     * @return string
272
     */
273
    public function text($name, $values = [], array $errors = [], array $attributes = [], $class = '')
274
    {
275
        return $this->input('text', $name, $values, $errors, $attributes, $class);
276
    }
277
278
    /**
279
     * Display a password field.
280
     *
281
     * @param string $name       Field name
282
     * @param array  $values     Form values
283
     * @param array  $errors     Form errors
284
     * @param array  $attributes HTML attributes
285
     * @param string $class      CSS class
286
     *
287
     * @return string
288
     */
289
    public function password($name, $values = [], array $errors = [], array $attributes = [], $class = '')
290
    {
291
        return $this->input('password', $name, $values, $errors, $attributes, $class);
292
    }
293
294
    /**
295
     * Display an email field.
296
     *
297
     * @param string $name       Field name
298
     * @param array  $values     Form values
299
     * @param array  $errors     Form errors
300
     * @param array  $attributes HTML attributes
301
     * @param string $class      CSS class
302
     *
303
     * @return string
304
     */
305
    public function email($name, $values = [], array $errors = [], array $attributes = [], $class = '')
306
    {
307
        return $this->input('email', $name, $values, $errors, $attributes, $class);
308
    }
309
310
    /**
311
     * Display a number field.
312
     *
313
     * @param string $name       Field name
314
     * @param array  $values     Form values
315
     * @param array  $errors     Form errors
316
     * @param array  $attributes HTML attributes
317
     * @param string $class      CSS class
318
     *
319
     * @return string
320
     */
321
    public function number($name, $values = [], array $errors = [], array $attributes = [], $class = '')
322
    {
323
        return $this->input('number', $name, $values, $errors, $attributes, $class);
324
    }
325
326
    /**
327
     * Display a numeric field (allow decimal number).
328
     *
329
     * @param string $name       Field name
330
     * @param array  $values     Form values
331
     * @param array  $errors     Form errors
332
     * @param array  $attributes HTML attributes
333
     * @param string $class      CSS class
334
     *
335
     * @return string
336
     */
337
    public function numeric($name, $values = [], array $errors = [], array $attributes = [], $class = '')
338
    {
339
        return $this->input('text', $name, $values, $errors, $attributes, $class.' form-numeric');
340
    }
341
342
    /**
343
     * Date field.
344
     *
345
     * @param string $label
346
     * @param string $name
347
     * @param array  $values
348
     * @param array  $errors
349
     * @param array  $attributes
350
     *
351
     * @return string
352
     */
353 View Code Duplication
    public function date($label, $name, array $values, array $errors = [], array $attributes = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
354
    {
355
        $userFormat = $this->dateParser->getUserDateFormat();
0 ignored issues
show
Documentation introduced by
The property dateParser does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
356
        $values = $this->dateParser->format($values, [$name], $userFormat);
0 ignored issues
show
Documentation introduced by
The property dateParser does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
357
        $attributes = array_merge(['placeholder="'.date($userFormat).'"'], $attributes);
358
359
        return $this->helper->form->label($label, $name).
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
360
            $this->helper->form->text($name, $values, $errors, $attributes, 'form-date');
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
361
    }
362
363
    /**
364
     * Datetime field.
365
     *
366
     * @param string $label
367
     * @param string $name
368
     * @param array  $values
369
     * @param array  $errors
370
     * @param array  $attributes
371
     *
372
     * @return string
373
     */
374 View Code Duplication
    public function datetime($label, $name, array $values, array $errors = [], array $attributes = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
375
    {
376
        $userFormat = $this->dateParser->getUserDateTimeFormat();
0 ignored issues
show
Documentation introduced by
The property dateParser does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
377
        $values = $this->dateParser->format($values, [$name], $userFormat);
0 ignored issues
show
Documentation introduced by
The property dateParser does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
378
        $attributes = array_merge(['placeholder="'.date($userFormat).'"'], $attributes);
379
380
        return $this->helper->form->label($label, $name).
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
381
            $this->helper->form->text($name, $values, $errors, $attributes, 'form-datetime');
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
382
    }
383
384
    /**
385
     * Display the form error class.
386
     *
387
     * @param array  $errors Error list
388
     * @param string $name   Field name
389
     *
390
     * @return string
391
     */
392
    private function errorClass(array $errors, $name)
393
    {
394
        return !isset($errors[$name]) ? '' : ' form-error';
395
    }
396
397
    /**
398
     * Display a list of form errors.
399
     *
400
     * @param array  $errors List of errors
401
     * @param string $name   Field name
402
     *
403
     * @return string
404
     */
405
    private function errorList(array $errors, $name)
406
    {
407
        $html = '';
408
409
        if (isset($errors[$name])) {
410
            $html .= '<ul class="form-errors">';
411
412
            foreach ($errors[$name] as $error) {
413
                $html .= '<li>'.$this->helper->text->e($error).'</li>';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
414
            }
415
416
            $html .= '</ul>';
417
        }
418
419
        return $html;
420
    }
421
422
    /**
423
     * Get an escaped form value.
424
     *
425
     * @param mixed  $values Values
426
     * @param string $name   Field name
427
     *
428
     * @return string
429
     */
430
    private function formValue($values, $name)
431
    {
432
        if (isset($values->$name)) {
433
            return 'value="'.$this->helper->text->e($values->$name).'"';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
434
        }
435
436
        return isset($values[$name]) ? 'value="'.$this->helper->text->e($values[$name]).'"' : '';
0 ignored issues
show
Documentation introduced by
The property helper does not exist on object<Jitamin\Helper\FormHelper>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
437
    }
438
}
439