Passed
Pull Request — html-like-rules (#68)
by Dmitriy
02:39 queued 41s
created

RequiredHtmlOptions   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
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 23
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A withAriaAttribute() 0 5 1
A getHtmlOptions() 0 5 2
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 ValidatorAwareTrait;
13
14
    private bool $ariaAttribute = false;
15
16 122
    public function __construct(Required $validator)
17
    {
18 122
        $this->validator = $validator;
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