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

TodayCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 38
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 3
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 TodayCommand extends Command
14
{
15
    /**
16
     * The signature of the command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'today';
21
22
    /**
23
     * The description of the command.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Show the scheduled games for today';
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
            $data = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
40
            $todayGames = $nfl->getTodayGames();
41
42
            if (is_null($todayGames)) {
43
                exit($this->line('Sorry, there is no games scheduled for today.'));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->line('Sorry, ther... scheduled for today.') 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...
44
            }
45
46
            $printer = new Printer($this);
47
48
            $printer->renderGamesList($todayGames);
49
        } catch (ErrorException $e) {
50
            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...
51
        }
52
    }
53
}
54