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

ButtonAttributes   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 40
ccs 11
cts 11
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 3
A form() 0 5 1
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