Passed
Pull Request — master (#192)
by Sergei
02:47
created

Image::alt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Field;
6
7
use Stringable;
8
use Yiisoft\Form\Field\Base\AbstractSimpleField;
9
use Yiisoft\Html\Html;
10
11
/**
12
 * @link https://html.spec.whatwg.org/multipage/input.html#image-button-state-(type=image)
13
 */
14
final class Image extends AbstractSimpleField
15
{
16
    private array $inputTagAttributes = [];
17
18
    /**
19
     * Provides the textual label for the button for users and user agents who cannot use the image.
20
     *
21
     * @link https://html.spec.whatwg.org/multipage/input.html#attr-input-alt
22
     */
23 2
    public function alt(?string $value): self
24
    {
25 2
        $new = clone $this;
26 2
        $new->inputTagAttributes['alt'] = $value;
27 2
        return $new;
28
    }
29
30
    public function width(int|string|Stringable|null $width): self
31
    {
32
        $new = clone $this;
33
        $new->inputTagAttributes['width'] = $width;
34
        return $new;
35
    }
36
37
    public function height(int|string|Stringable|null $height): self
38
    {
39
        $new = clone $this;
40
        $new->inputTagAttributes['height'] = $height;
41
        return $new;
42
    }
43
44
    /**
45
     * @link https://html.spec.whatwg.org/multipage/input.html#attr-input-src
46
     */
47 2
    public function src(?string $url): self
48
    {
49 2
        $new = clone $this;
50 2
        $new->inputTagAttributes['src'] = $url;
51 2
        return $new;
52
    }
53
54 3
    public function disabled(?bool $disabled = true): self
55
    {
56 3
        $new = clone $this;
57 3
        $new->inputTagAttributes['disabled'] = $disabled;
58 3
        return $new;
59
    }
60
61
    public function inputTagAttributes(array $attributes): self
62
    {
63
        $new = clone $this;
64
        $new->inputTagAttributes = $attributes;
65
        return $new;
66
    }
67
68 5
    protected function generateInput(): string
69
    {
70 5
        return Html::input(
71
            type: 'image',
72 5
            attributes: $this->inputTagAttributes
73 5
        )->render();
74
    }
75
}
76