Test Failed
Push — extract-attributes ( 6e6144...c9c1de )
by Dmitriy
07:22 queued 12s
created

PasswordInput::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Widget;
6
7
use Yiisoft\Form\FormModelInterface;
8
use Yiisoft\Widget\Widget;
9
10
final class PasswordInput extends Widget
11
{
12
    private FormModelInterface $data;
13
    private string $attribute;
14
    private array $options = [];
15
    private bool $noPlaceholder = false;
16
17
    /**
18
     * Generates a password input tag for the given form attribute.
19
     *
20
     * @return string the generated input tag,
21
     */
22
    public function run(): string
23
    {
24
        return Input::widget()
25
            ->type('password')
0 ignored issues
show
Bug introduced by
The method type() does not exist on Yiisoft\Widget\Widget. It seems like you code against a sub-type of Yiisoft\Widget\Widget such as Yiisoft\Form\Widget\ListBox or Yiisoft\Form\Widget\Input or Yiisoft\Form\Widget\ListInput or Yiisoft\Form\Widget\BooleanInput. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            ->/** @scrutinizer ignore-call */ type('password')
Loading history...
26
            ->config($this->data, $this->attribute, $this->options)
27
            ->noPlaceholder($this->noPlaceholder)
28
            ->run();
29
    }
30
31
    /**
32
     * Set form model, name and options for the widget.
33
     *
34
     * @param FormModelInterface $data Form model.
35
     * @param string $attribute Form model property this widget is rendered for.
36
     * @param array $options The HTML attributes for the widget container tag.See
37
     * See {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
38
     *
39
     * @return self
40
     */
41
    public function config(FormModelInterface $data, string $attribute, array $options = []): self
42
    {
43
        $new = clone $this;
44
        $new->data = $data;
45
        $new->attribute = $attribute;
46
        $new->options = $options;
47
        return $new;
48
    }
49
50
    /**
51
     * Focus on the control (put cursor into it) when the page loads.
52
     * Only one form element could be in focus at the same time.
53
     *
54
     * @param bool $value
55
     *
56
     * @return self
57
     */
58
    public function autofocus(bool $value = true): self
59
    {
60
        $new = clone $this;
61
        $new->options['autofocus'] = $value;
62
        return $new;
63
    }
64
65
    /**
66
     * Set whether the element is disabled or not.
67
     *
68
     * If this attribute is set to `true`, the element is disabled. Disabled elements are usually drawn with grayed-out
69
     * text.
70
     * If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event
71
     * will not fire. In the case of form elements, it will not be submitted. Do not set the attribute to true, as
72
     * this will suggest you can set it to false to enable the element again, which is not the case.
73
     *
74
     * @param bool $value
75
     *
76
     * @return self
77
     */
78
    public function disabled(bool $value = true): self
79
    {
80
        $new = clone $this;
81
        $new->options['disabled'] = $value;
82
        return $new;
83
    }
84
85
    /**
86
     * Specifies the form element the tag input element belongs to. The value of this attribute must be the id
87
     * attribute of a {@see Form} element in the same document.
88
     *
89
     * @param string $value
90
     *
91
     * @return self
92
     */
93
    public function form(string $value): self
94
    {
95
        $new = clone $this;
96
        $new->options['form'] = $value;
97
        return $new;
98
    }
99
100
    /**
101
     * The minimum number of characters (as UTF-16 code units) the user can enter into the text input.
102
     *
103
     * This must be an non-negative integer value smaller than or equal to the value specified by maxlength.
104
     * If no minlength is specified, or an invalid value is specified, the text input has no minimum length.
105
     *
106
     * @param int $value
107
     *
108
     * @return self
109
     */
110
    public function minlength(int $value): self
111
    {
112
        $new = clone $this;
113
        $new->options['minlength'] = $value;
114
        return $new;
115
    }
116
117
    /**
118
     * The maxlength attribute defines the maximum number of characters (as UTF-16 code units) the user can enter into
119
     * an tag input.
120
     *
121
     * If no maxlength is specified, or an invalid value is specified, the tag input has no maximum length.
122
     *
123
     * @param int $value
124
     *
125
     * @return self
126
     */
127
    public function maxlength(int $value): self
128
    {
129
        $new = clone $this;
130
        $new->options['maxlength'] = $value;
131
        return $new;
132
    }
133
134
    /**
135
     * Allows you to disable placeholder.
136
     *
137
     * @param bool $value
138
     *
139
     * @return self
140
     */
141
    public function noPlaceholder(bool $value = true): self
142
    {
143
        $new = clone $this;
144
        $new->noPlaceholder = $value;
145
        return $new;
146
    }
147
148
    /**
149
     * The pattern attribute, when specified, is a regular expression that the input's value must match in order for
150
     * the value to pass constraint validation. It must be a valid JavaScript regular expression, as used by the
151
     * RegExp type.
152
     *
153
     * @param string $value
154
     *
155
     * @return self
156
     */
157
    public function pattern(string $value): self
158
    {
159
        $new = clone $this;
160
        $new->options['pattern'] = $value;
161
        return $new;
162
    }
163
164
    /**
165
     * It allows defining placeholder.
166
     *
167
     * @param string $value
168
     *
169
     * @return self
170
     */
171
    public function placeholder(string $value): self
172
    {
173
        $new = clone $this;
174
        $new->options['placeholder'] = $value;
175
        return $new;
176
    }
177
178
    /**
179
     * A Boolean attribute which, if present, means this field cannot be edited by the user.
180
     * Its value can, however, still be changed by JavaScript code directly setting the HTMLInputElement.value
181
     * property.
182
     *
183
     * @param bool $value
184
     *
185
     * @return self
186
     */
187
    public function readOnly(bool $value = true): self
188
    {
189
        $new = clone $this;
190
        $new->options['readonly'] = $value;
191
        return $new;
192
    }
193
194
    /**
195
     * If it is required to fill in a value in order to submit the form.
196
     *
197
     * @param bool $value
198
     *
199
     * @return self
200
     */
201
    public function required(bool $value = true): self
202
    {
203
        $new = clone $this;
204
        $new->options['required'] = $value;
205
        return $new;
206
    }
207
208
    /**
209
     * The tabindex global attribute indicates that its element can be focused, and where it participates in sequential
210
     * keyboard navigation (usually with the Tab key, hence the name).
211
     *
212
     * It accepts an integer as a value, with different results depending on the integer's value:
213
     *
214
     * - A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard
215
     * navigation, but could be focused with Javascript or visually. It's mostly useful to create accessible widgets
216
     * with JavaScript.
217
     * - tabindex="0" means that the element should be focusable in sequential keyboard navigation, but its order is
218
     * defined by the document's source order.
219
     * - A positive value means the element should be focusable in sequential keyboard navigation, with its order
220
     * defined by the value of the number. That is, tabindex="4" is focused before tabindex="5", but after tabindex="3".
221
     *
222
     * @param int $value
223
     *
224
     * @return self
225
     */
226
    public function tabIndex(int $value = 0): self
227
    {
228
        $new = clone $this;
229
        $new->options['tabindex'] = $value;
230
        return $new;
231
    }
232
233
    /**
234
     * The title global attribute contains text representing advisory information related to the element it belongs to.
235
     *
236
     * @param string $value
237
     *
238
     * @return self
239
     */
240
    public function title(string $value): self
241
    {
242
        $new = clone $this;
243
        $new->options['title'] = $value;
244
        return $new;
245
    }
246
}
247