Passed
Push — master ( ef6f5d...60f4bc )
by Alexander
02:52
created

ButtonAttributes::build()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Widget\Attribute;
6
7
use Yiisoft\Html\Html;
8
9
abstract class ButtonAttributes extends GlobalAttributes
10
{
11
    /**
12
     * Specifies the form element the tag input element belongs to. The value of this attribute must be the id
13
     * attribute of a {@see Form} element in the same document.
14
     *
15
     * @param string $value
16
     *
17
     * @return static
18
     *
19
     * @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fae-form
20
     */
21 6
    public function form(string $value): self
22
    {
23 6
        $new = clone $this;
24 6
        $new->attributes['form'] = $value;
25 6
        return $new;
26
    }
27
28
    /**
29
     * Set build attributes for the widget.
30
     *
31
     * @param array $attributes $value
32
     * @param string $suffix The suffix of the attribute name.
33
     *
34
     * @return array
35
     */
36 74
    protected function build(array $attributes, string $suffix): array
37
    {
38 74
        $id = Html::generateId('w') . $suffix;
39
40 74
        if (!array_key_exists('id', $attributes)) {
41 64
            $attributes['id'] = $id;
42
        }
43
44 74
        if (!array_key_exists('name', $attributes)) {
45 64
            $attributes['name'] = $id;
46
        }
47
48 74
        return $attributes;
49
    }
50
}
51