Completed
Push — master ( b38e7e...9a907a )
by Sophie
02:32
created

FieldText::setPattern()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace hemio\form;
4
5
class FieldText extends Abstract_\FormFieldInput {
6
7
    public function getInputType() {
8
        return 'text';
9
    }
10
11
    /**
12
     *
13
     * @param string $placeholder
14
     */
15
    public function setPlaceholder($placeholder) {
16
        $this->getControlElement()->setAttribute('placeholder', $placeholder);
17
    }
18
19
    /**
20
     *
21
     * @param boolean $allow
22
     */
23
    public function setAllowMultiple($allow = true) {
24
        $this->getControlElement()->setAttribute('multiple', (boolean) $allow);
25
    }
26
27
    /**
28
     *
29
     * @param boolean $required
30
     */
31
    public function setRequired($required = true) {
32
        $this->addValidityCheck(new CheckMinLength(1));
33
        $this->required = $required;
34
        $this->getControlElement()->setAttribute('required', (boolean) $required);
35
    }
36
37
    public function setPattern($pattern, $message = null) {
38
        $this->addValidityCheck(new CheckPattern('pattern', $pattern, $message));
0 ignored issues
show
Documentation introduced by
'pattern' is of type string, but the function expects a object<hemio\form\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39
        $this->getControlElement()->setAttribute('pattern', $pattern);
40
        if ($message !== null)
41
            $this->getControlElement()->setAttribute('title', $message);
42
    }
43
44
}
45