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

RequiredHtmlOptions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getHtmlOptions() 0 5 2
A withAriaAttribute() 0 5 1
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