Completed
Push — master ( 80f3c8...09c568 )
by Hans
05:45
created

Ticket::getDivisor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace HansOtt\Lottery;
5
6
final class Ticket
7
{
8
    private $numerator;
9
10
    private $divisor;
11
12
    /**
13
     * Ticket constructor.
14
     *
15
     * @param int $numerator
16
     * @param int $divisor
17
     */
18 4
    public function __construct(int $numerator, int $divisor)
19
    {
20 4
        $this->assertValidNumerator($numerator);
21 3
        $this->assertValidDivisor($numerator, $divisor);
22 3
        $this->numerator = $numerator;
23 3
        $this->divisor = $divisor;
24 3
    }
25
26 4
    private function assertValidNumerator(int $numerator)
27
    {
28 4
        if ($numerator <= 0) {
29 2
            throw new InvalidArgumentException(
30 2
                sprintf(
31 2
                    'Expected a positive $numerator, but instead got: %d',
32 2
                    $numerator
33
                )
34
            );
35
        }
36 3
    }
37
38 3
    private function assertValidDivisor(int $numerator, int $divisor)
39
    {
40 3
        if ($divisor <= 0) {
41
            throw new InvalidArgumentException(
42
                sprintf(
43
                    'Expected a positive $divisor, but instead got: %d',
44
                    $divisor
45
                )
46
            );
47
        }
48
49 3
        if ($divisor < $numerator) {
50 1
            throw new InvalidArgumentException(
51 1
                sprintf(
52 1
                    'Expected a $divisor that is equal or greater than the $numerator, but instead got: %d < %d',
53 1
                    $divisor,
54 1
                    $numerator
55
                )
56
            );
57
        }
58 3
    }
59
60 1
    public function getNumerator() : int
61
    {
62 1
        return $this->numerator;
63
    }
64
65 1
    public function getDivisor() : int
66
    {
67 1
        return $this->divisor;
68
    }
69
}
70