Passed
Pull Request — master (#192)
by Alexander
02:53
created

MinMaxLengthTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A minlength() 0 5 1
A maxlength() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Field\Base;
6
7
/**
8
 * @psalm-require-extends AbstractField
9
 */
10
trait MinMaxLengthTrait
11
{
12
    /**
13
     * Maximum length of value.
14
     *
15
     * @param int $value A limit on the number of characters a user can input.
16
     *
17
     * @link https://html.spec.whatwg.org/multipage/input.html#attr-input-maxlength
18
     * @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-maxlength
19
     */
20 2
    public function maxlength(int $value): static
21
    {
22 2
        $new = clone $this;
23 2
        $new->inputTagAttributes['maxlength'] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property inputTagAttributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24 2
        return $new;
25
    }
26
27
    /**
28
     * Minimum length of value.
29
     *
30
     * @param int $value A lower bound on the number of characters a user can input.
31
     *
32
     * @link https://html.spec.whatwg.org/multipage/input.html#attr-input-minlength
33
     * @link https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-minlength
34
     */
35 2
    public function minlength(int $value): static
36
    {
37 2
        $new = clone $this;
38 2
        $new->inputTagAttributes['minlength'] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property inputTagAttributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39 2
        return $new;
40
    }
41
}
42