Domino::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\DominoGame\Value;
6
7
/**
8
 * @author  Alex Patterson <[email protected]>
9
 * @package Arp\DominoGame\Value
10
 */
11
class Domino
12
{
13
    /**
14
     * @var int
15
     */
16
    private int $topTile;
17
18
    /**
19
     * @var int
20
     */
21
    private int $bottomTile;
22
23
    /**
24
     * @param int $topTile
25
     * @param int $bottomTile
26
     */
27
    public function __construct(int $topTile, int $bottomTile)
28
    {
29
        $this->topTile = $topTile;
30
        $this->bottomTile = $bottomTile;
31
    }
32
33
    /**
34
     * @return string
35
     */
36
    public function getName(): string
37
    {
38
        return $this->topTile . '-' . $this->bottomTile;
39
    }
40
41
    /**
42
     * Check if the top and bottom dots are equal, a double.
43
     *
44
     * @return bool
45
     */
46
    public function isDouble(): bool
47
    {
48
        return $this->topTile === $this->bottomTile;
49
    }
50
51
    /**
52
     * Return the number of dots in the 'top' square.
53
     *
54
     * @return int
55
     */
56
    public function getTopTile(): int
57
    {
58
        return $this->topTile;
59
    }
60
61
    /**
62
     * Return the number of dots in the 'bottom' square.
63
     *
64
     * @return int
65
     */
66
    public function getBottomTile(): int
67
    {
68
        return $this->bottomTile;
69
    }
70
71
    /**
72
     * Return the sum of the domino's dots.
73
     *
74
     * @return int
75
     */
76
    public function getValue(): int
77
    {
78
        return ($this->topTile + $this->bottomTile);
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function __toString()
85
    {
86
        return $this->getName();
87
    }
88
}
89