Completed
Push — master ( 3ec9c1...244937 )
by Max
02:44
created

Game::isFinished()   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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NFLScores\Models;
4
5
use NFLScores\Exceptions\NonExistingPropertyException;
6
7
/**
8
 * Represents a NFL game.
9
 */
10
class Game
11
{
12
    /**
13
     * The data about the game.
14
     *
15
     * @var array
16
     */
17
    private $data;
18
19
    /**
20
     * Populate the $data array.
21
     *
22
     * @param array $data
23
     */
24 1
    public function __construct(array $data)
25
    {
26 1
        $this->data = $data;
27 1
    }
28
29
    /**
30
     * Return the index stored in the $data
31
     * property, if doesn't exist throw an
32
     * exception.
33
     *
34
     * @param string $name
35
     *
36
     * @throws \NFLScores\Exceptions\NonExistingPropertyException
37
     *
38
     * @return mixed
39
     */
40 17
    public function __get(string $name)
41
    {
42 17
        if (array_key_exists($name, $this->data)) {
43 17
            return $this->data[$name];
44
        }
45
46 1
        throw new NonExistingPropertyException(sprintf('There is not property called %s in this object', $name));
47
    }
48
49
    /**
50
     * Return the the current down,
51
     * if the game hasn't started return null.
52
     *
53
     * @return string|null
54
     */
55 4
    public function getCurrentDown(): ?string
56
    {
57 4
        if ($this->score['down'] === 0) {
0 ignored issues
show
Bug Best Practice introduced by
The property score does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
58 1
            return null;
59
        }
60
61 4
        return sprintf(
62 4
            '%d%s & %d',
63 4
            $this->score['down'],
64 4
            getOrdinalSuffix($this->score['down']),
65 4
            $this->score['yardsToGo']
66
        );
67
    }
68
69
    /**
70
     * Return the team with the current
71
     * ball possesion, if the game hasn't
72
     * started return null.
73
     *
74
     * @return string|null
75
     */
76 4
    public function getPossesionTeam(): ?string
77
    {
78 4
        return !$this->isFinished() ? $this->score['possessionTeamAbbr'] : null;
0 ignored issues
show
Bug Best Practice introduced by
The property score does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
79
    }
80
81
    /**
82
     * Return the the current quarter,
83
     * if the game hasn't started return null.
84
     *
85
     * @return string|null
86
     */
87 4
    public function getCurrentQuarter(): ?string
88
    {
89 4
        return $this->score['phaseDescription'];
0 ignored issues
show
Bug Best Practice introduced by
The property score does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
90
    }
91
92
    /**
93
     * Return whether the game is
94
     * finished or not.
95
     *
96
     * @return bool
97
     */
98 7
    public function isFinished(): bool
99
    {
100 7
        return in_array($this->score['phase'], ['FINAL', 'FINAL OVERTIME']);
0 ignored issues
show
Bug Best Practice introduced by
The property score does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
101
    }
102
103
    /**
104
     * Return whether the game is
105
     * suspended or not.
106
     *
107
     * @return bool
108
     */
109
    public function isSuspended(): bool
110
    {
111
        return $this->score['phase'] === 'SUSPENDED';
0 ignored issues
show
Bug Best Practice introduced by
The property score does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
112
    }
113
}
114