Test Failed
Push — validate-by-validator ( a015d2 )
by Dmitriy
03:11
created

RequiredHtmlOptions::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
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
    public function __construct(Required $rule)
17
    {
18
        $this->rule = $rule;
19
    }
20
21
    public function withAriaAttribute(bool $value): self
22
    {
23
        $new = clone $this;
24
        $new->ariaAttribute = $value;
25
        return $new;
26
    }
27
28
    public function getHtmlOptions(): array
29
    {
30
        return [
31
            'required' => true,
32
            'aria-required' => $this->ariaAttribute ? 'true' : false,
33
        ];
34
    }
35
}
36