Passed
Pull Request — master (#519)
by
unknown
02:45
created

Compare::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 10
dl 0
loc 21
ccs 9
cts 9
cp 1
crap 2
rs 10

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
9
/**
10
 * Defines validation options to check that the specified value matches with another value or attribute.
11
 *
12
 * The value being compared with a constant {@see Compare::$targetValue}, which is set
13
 * in the constructor.
14
 *
15
 * It supports different comparison operators, specified via the {@see Compare::$operator}.
16
 *
17
 * There are shortcut classes to use instead of specifying operator manually:
18
 *
19
 * - {@see Equal} is a shortcut for `new CompareOperator(operator: '==')` and `new CompareOperator(operator: '===')`.
20
 * - {@see NotEqual} is a shortcut for `new CompareOperator(operator: '!=')` and `new CompareOperator(operator: '!==')`.
21
 * - {@see GreaterThan} is a shortcut for `new CompareTo(operator: '>')`.
22
 * - {@see GreaterThanOrEqual} is a shortcut for `new CompareTo(operator: '>=')`.
23
 * - {@see LessThan} is a shortcut for `new CompareTo(operator: '<')`.
24
 * - {@see LessThanOrEqual} is a shortcut for `new CompareTo(operator: '<=')`.
25
 *
26
 * The default comparison function is based on string values, which means the values
27
 * are compared byte by byte. When comparing numbers, make sure to change {@see Compare::$type} to
28
 * {@see Compare::TYPE_NUMBER} to enable numeric comparison.
29
 *
30
 * @see CompareHandler
31
 */
32
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
33
final class Compare extends AbstractCompare
34
{
35
    public function getName(): string
36
    {
37
        return 'compareTo';
38
    }
39
}
40