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

Ticket   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 64
c 0
b 0
f 0
ccs 26
cts 30
cp 0.8667
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getNumerator() 0 4 1
A getDivisor() 0 4 1
A assertValidNumerator() 0 11 2
A assertValidDivisor() 0 21 3
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