Printer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Test Coverage

Coverage 97.96%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 133
ccs 48
cts 49
cp 0.9796
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A buildScoreBoardRow() 0 10 1
A printScoreBoardHeader() 0 18 2
A printScoreBoard() 0 13 1
A renderGamesList() 0 15 1
A renderScoreBoard() 0 8 2
A __construct() 0 3 1
1
<?php
2
3
namespace NFLScores\Utilities;
4
5
use LaravelZero\Framework\Commands\Command;
6
use NFLScores\Models\Game;
7
use PHPCollections\Collections\GenericList;
8
9
/**
10
 * Utility class for printing
11
 * elements into the console.
12
 */
13
class Printer
14
{
15
    /**
16
     * The command which will be execute.
17
     *
18
     * @var \LaravelZero\Framework\Commands\Command
19
     */
20
    private $command;
21
22
    /**
23
     * Initialize values.
24
     *
25
     * @param \LaravelZero\Framework\Commands\Command
26
     */
27 8
    public function __construct(Command $command)
28
    {
29 8
        $this->command = $command;
30 8
    }
31
32
    /**
33
     * Return an array with the name and
34
     * score of a specific team.
35
     *
36
     * @param string $abbr
37
     * @param array  $score
38
     *
39
     * @return array
40
     */
41 6
    private function buildScoreBoardRow(string $abbr, array $score): array
42
    {
43
        return [
44 6
            $abbr,
45 6
            $score['pointQ1'],
46 6
            $score['pointQ2'],
47 6
            $score['pointQ3'],
48 6
            $score['pointQ4'],
49 6
            $score['pointOT'],
50 6
            $score['pointTotal'],
51
        ];
52
    }
53
54
    /**
55
     * Build and print a game' scoreboard
56
     * into the terminal.
57
     *
58
     * @param \NFLScores\Models\Game $game
59
     *
60
     * @return void
61
     */
62 6
    private function printScoreBoard(Game $game): void
63
    {
64 6
        $this->printScoreBoardHeader($game);
65
66 6
        $this->command->table(
67 6
            ['', '1', '2', '3', '4', 'OT', 'T'],
68
            [
69 6
                $this->buildScoreBoardRow($game->gameSchedule['homeTeamAbbr'], $game->score['homeTeamScore']),
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...
Bug Best Practice introduced by
The property gameSchedule does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
70 6
                $this->buildScoreBoardRow($game->gameSchedule['visitorTeamAbbr'], $game->score['visitorTeamScore']),
71
            ]
72
        );
73
74 6
        $this->command->line("\n");
75 6
    }
76
77
    /**
78
     * Build and print the scoreboard header.
79
     *
80
     * @param \NFLScores\Models\Game $game
81
     *
82
     * @return void
83
     */
84 6
    public function printScoreBoardHeader(Game $game)
85
    {
86 6
        $this->command->line(
87 6
            sprintf(
88 6
                '%s VS %s @ %s',
89 6
                $game->gameSchedule['homeTeamAbbr'],
0 ignored issues
show
Bug Best Practice introduced by
The property gameSchedule does not exist on NFLScores\Models\Game. Since you implemented __get, consider adding a @property annotation.
Loading history...
90 6
                $game->gameSchedule['visitorTeamAbbr'],
91 6
                $game->gameSchedule['site']['siteFullname']
92
            )
93
        );
94
95 6
        if (!$game->isFinished()) {
96 3
            $this->command->line(sprintf(
97 3
                '%s | %s | %s %s',
98 3
                $game->getCurrentQuarter(),
99 3
                $game->score['time'],
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...
100 3
                $game->getPossesionTeam(),
101 3
                $game->getCurrentDown()
102
            ));
103
        }
104 6
    }
105
106
    /**
107
     * Print a table with a list of games.
108
     *
109
     * @param \PHPCollections\Collections\GenericList $gameCollection
110
     *
111
     * @return void
112
     */
113 2
    public function renderGamesList(?GenericList $gameCollection): void
114
    {
115 2
        $data = [];
116
117
        $gameCollection->forEach(function ($game, $key) use (&$data) {
0 ignored issues
show
Bug introduced by
The method forEach() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

117
        $gameCollection->/** @scrutinizer ignore-call */ 
118
                         forEach(function ($game, $key) use (&$data) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

117
        $gameCollection->forEach(function ($game, /** @scrutinizer ignore-unused */ $key) use (&$data) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118 2
            array_push($data, [
119 2
                $game->gameSchedule['homeTeamAbbr'],
120 2
                $game->gameSchedule['visitorTeamAbbr'],
121 2
                $game->gameSchedule['site']['siteFullname'],
122 2
                $game->gameSchedule['gameDate'],
123 2
                sprintf('%s ET', $game->gameSchedule['gameTimeEastern']),
124
            ]);
125 2
        });
126
127 2
        $this->command->table(['Home', 'Visitor', 'Stadium', 'Date', 'Hour'], $data);
128 2
    }
129
130
    /**
131
     * Print a collection of game'
132
     * scoreboards into the terminal.
133
     *
134
     * @param PHPCollections\Collections\GenericList
135
     *
136
     * @return void
137
     */
138 6
    public function renderScoreBoard(?GenericList $games): void
139
    {
140 6
        if (is_null($games)) {
141
            exit($this->command->line('Sorry, there is no games right now.'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->command->line('So...s no games right now.') targeting Illuminate\Console\Command::line() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
142
        }
143
144
        $games->forEach(function ($game, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

144
        $games->forEach(function ($game, /** @scrutinizer ignore-unused */ $key) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
145 6
            $this->printScoreBoard($game);
146 6
        });
147 6
    }
148
}
149