Test Failed
Pull Request — master (#160)
by Wilmer
02:22
created

GlobalAttributes::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Widget\Attribute;
6
7
use Stringable;
8
use Yiisoft\Html\Html;
9
10
trait GlobalAttributes
11
{
12
    protected array $attributes = [];
13
14
    /**
15
     * Focus on the control (put cursor into it) when the page loads.
16
     * Only one form element could be in focus at the same time.
17
     *
18
     * @return static
19
     *
20
     * @link https://www.w3.org/TR/html52/sec-forms.html#autofocusing-a-form-control-the-autofocus-attribute
21
     */
22
    public function autofocus(): self
23
    {
24
        $new = clone $this;
25
        $new->attributes['autofocus'] = true;
26
        return $new;
27
    }
28
29
    /**
30
     * The HTML attributes. The following special options are recognized.
31
     *
32
     * @param array $values Attribute values indexed by attribute names.
33
     *
34
     * @return static
35
     *
36
     * See {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered.
37
     */
38
    public function attributes(array $values): self
39
    {
40
        $new = clone $this;
41
        $new->attributes = array_merge($new->attributes, $values);
42
        return $new;
43
    }
44
45
    /**
46
     * Set CSS class of the field widget.
47
     *
48
     * @param string $class
49
     *
50
     * @return static
51
     */
52
    public function class(string $class): self
53
    {
54
        $new = clone $this;
55
        Html::addCssClass($new->attributes, $class);
56
        return $new;
57
    }
58
59
    /**
60
     * Set whether the element is disabled or not.
61
     *
62
     * If this attribute is set to `true`, the element is disabled. Disabled elements are usually drawn with grayed-out
63
     * text.
64
     * If the element is disabled, it does not respond to user actions, it cannot be focused, and the command event
65
     * will not fire. In the case of form elements, it will not be submitted. Do not set the attribute to true, as
66
     * this will suggest you can set it to `false` to enable the element again, which is not the case.
67
     *
68
     * @return static
69
     *
70
     * @link https://www.w3.org/TR/html52/sec-forms.html#element-attrdef-disabledformelements-disabled
71
     */
72
    public function disabled(): self
73
    {
74
        $new = clone $this;
75
        $new->attributes['disabled'] = true;
76
        return $new;
77
    }
78
79
    /**
80
     * Set the ID of the widget.
81
     *
82
     * @param string|null $id
83
     *
84
     * @return static
85
     *
86
     * @link https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute
87
     */
88
    public function id(?string $id): self
89
    {
90
        $new = clone $this;
91
        $new->attributes['id'] = $id;
92
        return $new;
93
    }
94
95
    /**
96
     * The name part of the name/value pair associated with this element for the purposes of form submission.
97
     *
98
     * @param string|null The name of the widget.
0 ignored issues
show
Bug introduced by
The type Yiisoft\Form\Widget\Attribute\The was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
99
     *
100
     * @return static
101
     *
102
     * @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-name
103
     */
104
    public function name(?string $value): self
105
    {
106
        $new = clone $this;
107
        $new->attributes['name'] = $value;
108
        return $new;
109
    }
110
111
    /**
112
     * The tabindex global attribute indicates that its element can be focused, and where it participates in sequential
113
     * keyboard navigation (usually with the Tab key, hence the name).
114
     *
115
     * It accepts an integer as a value, with different results depending on the integer's value:
116
     *
117
     * - A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard
118
     * navigation, but could be focused with Javascript or visually. It's mostly useful to create accessible widgets
119
     * with JavaScript.
120
     * - tabindex="0" means that the element should be focusable in sequential keyboard navigation, but its order is
121
     * defined by the document's source order.
122
     * - A positive value means the element should be focusable in sequential keyboard navigation, with its order
123
     * defined by the value of the number. That is, tabindex="4" is focused before tabindex="5", but after tabindex="3".
124
     *
125
     * @param int $value
126
     *
127
     * @return static
128
     *
129
     * @link https://html.spec.whatwg.org/multipage/interaction.html#attr-tabindex
130
     */
131
    public function tabIndex(int $value): self
132
    {
133
        $new = clone $this;
134
        $new->attributes['tabindex'] = $value;
135
        return $new;
136
    }
137
138
    /**
139
     * The title global attribute contains text representing advisory information related to the element it belongs to.
140
     *
141
     * @param string $value
142
     *
143
     * @return static
144
     *
145
     * @link https://html.spec.whatwg.org/multipage/dom.html#attr-title
146
     */
147
    public function title(string $value): self
148
    {
149
        $new = clone $this;
150
        $new->attributes['title'] = $value;
151
        return $new;
152
    }
153
154
    /**
155
     * The value of the radio button.
156
     *
157
     * @param scalar|Stringable|null $value
158
     *
159
     * @return static
160
     *
161
     * @link https://html.spec.whatwg.org/multipage/input.html#attr-input-value
162
     */
163
    public function value($value): self
164
    {
165
        $new = clone $this;
166
        $new->attributes['value'] = $value;
167
        return $new;
168
    }
169
}
170