Passed
Pull Request — master (#534)
by
unknown
02:44
created

Integer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
nc 1
nop 10
dl 0
loc 23
cc 1
rs 9.9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use Attribute;
8
use Closure;
9
10
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
11
final class Integer extends AbstractNumber
12
{
13
    public function __construct(
14
        float|int|null $min = null,
15
        float|int|null $max = null,
16
        string $incorrectInputMessage = 'The allowed types are integer, float and string.',
17
        string $notNumberMessage = 'Value must be an integer.',
18
        string $tooSmallMessage = 'Value must be no less than {min}.',
19
        string $tooBigMessage = 'Value must be no greater than {max}.',
20
        string $pattern = '/^\s*[+-]?\d+\s*$/',
21
        mixed $skipOnEmpty = null,
22
        bool $skipOnError = false,
23
        Closure|null $when = null,
24
    ) {
25
        parent::__construct(
26
            min: $min,
27
            max: $max,
28
            incorrectInputMessage: $incorrectInputMessage,
29
            notNumberMessage: $notNumberMessage,
30
            tooSmallMessage: $tooSmallMessage,
31
            tooBigMessage: $tooBigMessage,
32
            pattern: $pattern,
33
            skipOnEmpty: $skipOnEmpty,
34
            skipOnError: $skipOnError,
35
            when: $when,
36
        );
37
    }
38
39
    public function getName(): string
40
    {
41
        return 'integer';
42
    }
43
}
44