Passed
Push — master ( 8ba30c...5485cd )
by Oleg
03:02
created

RangeConstraint::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DFCodeGeneration\Generator\Tests;
5
6
use PHPUnit\Framework\Constraint\Constraint;
7
8
class RangeConstraint extends Constraint
9
{
10
    /**
11
     * @var int
12
     */
13
    private $from;
14
    /**
15
     * @var int
16
     */
17
    private $to;
18
19
    public function __construct(int $from, int $to)
20
    {
21
        parent::__construct();
22
        $this->from = $from;
23
        $this->to = $to;
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function toString(): string
30
    {
31
        return 'in range';
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    protected function matches($other): bool
38
    {
39
        return $other >= $this->from && $other <= $this->to;
40
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45
    protected function failureDescription($other): string
46
    {
47
        return \sprintf(
48
            '%s is not in range between %s and %s',
49
            $this->exporter->shortenedExport($other),
50
            $this->from,
51
            $this->to
52
        );
53
    }
54
}
55