Passed
Push — rename-getters ( eab17b )
by Dmitriy
02:49
created

RequiredHtmlOptions::getHtmlOptions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\HtmlOptions;
6
7
use Yiisoft\Validator\Rule\Required;
8
use Yiisoft\Validator\RuleInterface;
9
10
final class RequiredHtmlOptions implements HtmlOptionsProvider, RuleInterface
11
{
12
    use RuleAwareTrait;
13
14
    private bool $ariaAttribute = false;
15
16 122
    public function __construct(Required $rule)
17
    {
18 122
        $this->rule = $rule;
19 122
    }
20
21 116
    public function withAriaAttribute(bool $value): self
22
    {
23 116
        $new = clone $this;
24 116
        $new->ariaAttribute = $value;
25 116
        return $new;
26
    }
27
28 19
    public function getHtmlOptions(): array
29
    {
30
        return [
31 19
            'required' => true,
32 19
            'aria-required' => $this->ariaAttribute ? 'true' : false,
33
        ];
34
    }
35
}
36