Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — master (#1062)
by Henrique
03:30
created

AbstractComparison::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of Respect/Validation.
5
 *
6
 * (c) Alexandre Gomes Gaigalas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the "LICENSE.md"
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Respect\Validation\Rules;
15
16
use Respect\Validation\Helpers\ComparisonHelper;
17
18
/**
19
 * Abstract class to help on creating rules that compare value.
20
 *
21
 * @author Henrique Moody <[email protected]>
22
 */
23
abstract class AbstractComparison extends AbstractRule
24
{
25
    use ComparisonHelper;
26
27
    /**
28
     * @var mixed
29
     */
30
    private $compareTo;
31
32
    /**
33
     * Initializes the rule by setting the value to be compared to the input.
34
     *
35
     * @param mixed $maxValue
36
     */
37 12
    public function __construct($maxValue)
38
    {
39 12
        $this->compareTo = $maxValue;
40 12
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 82
    public function validate($input): bool
46
    {
47 82
        $left = $this->toComparable($input);
48 82
        $right = $this->toComparable($this->compareTo);
49
50 82
        if (!$this->isAbleToCompareValues($left, $right)) {
51 9
            return false;
52
        }
53
54 73
        return $this->compare($left, $right);
55
    }
56
57
    /**
58
     * Compare both values and return whether the comparison is valid or not.
59
     *
60
     * @param mixed $left
61
     * @param mixed $right
62
     *
63
     * @return bool
64
     */
65
    abstract protected function compare($left, $right): bool;
66
}
67