Completed
Push — master ( 652e57...3ec9c1 )
by Max
03:33
created

FinishedCommand::handle()   A

Complexity

Conditions 3
Paths 8

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 8
nop 0
dl 0
loc 13
ccs 0
cts 9
cp 0
crap 12
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace NFLScores\Commands;
4
5
use DateTime;
6
use DateTimeZone;
7
use ErrorException;
8
use LaravelZero\Framework\Commands\Command;
9
use NFLScores\Http\NFLHttpClient;
10
use NFLScores\Models\NFL;
11
use NFLScores\Utilities\Printer;
12
13
class FinishedCommand extends Command
14
{
15
    /**
16
     * The signature of the command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'finished {team?}';
21
22
    /**
23
     * The description of the command.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Show today\'s finished games';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return void
33
     */
34
    public function handle(): void
35
    {
36
        $nfl = new NFL(new NFLHttpClient(), new DateTime('now', new DateTimeZone('US/Eastern')));
37
38
        try {
39
            $games = (!is_null($this->argument('team')))
40
                ? $nfl->getFinishedGameByTeam($this->argument('team'))
0 ignored issues
show
Bug introduced by
It seems like $this->argument('team') can also be of type null and string[]; however, parameter $team of NFLScores\Models\NFL::getFinishedGameByTeam() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

40
                ? $nfl->getFinishedGameByTeam(/** @scrutinizer ignore-type */ $this->argument('team'))
Loading history...
41
                : $nfl->getFinishedGames();
42
43
            $printer = new Printer($this);
44
            $printer->renderScoreBoard($games);
45
        } catch (ErrorException $e) {
46
            exit($this->line('Sorry, there was a problem fetching the remote data.'));
0 ignored issues
show
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...
Bug introduced by
Are you sure the usage of $this->line('Sorry, ther...hing the remote data.') 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...
47
        }
48
    }
49
}
50