Passed
Push — master ( 13f560...b9fd0b )
by Orkhan
02:14
created

RateCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.9666
1
<?php
2
3
namespace Orkhanahmadov\LaravelCurrencylayer\Commands;
4
5
use Illuminate\Console\Command;
6
use Orkhanahmadov\LaravelCurrencylayer\Currencylayer;
7
8
class RateCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'currencylayer:rate 
16
                            {source : Source currency code} 
17
                            {date : Date for currency rates} 
18
                            {currencies* : Target currency codes}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Gets live rates for currencies';
26
27
    /**
28
     * Create a new command instance.
29
     *
30
     * @return void
31
     */
32
    public function __construct()
33
    {
34
        parent::__construct();
35
    }
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @param Currencylayer $currencylayer
41
     *
42
     * @return mixed
43
     */
44
    public function handle(Currencylayer $currencylayer)
45
    {
46
        $rates = $currencylayer->rate(
47
            $this->argument('source'),
0 ignored issues
show
Bug introduced by
It seems like $this->argument('source') can also be of type string[]; however, parameter $source of Orkhanahmadov\LaravelCur...r\Currencylayer::rate() does only seem to accept Orkhanahmadov\LaravelCur...\Models\Currency|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

47
            /** @scrutinizer ignore-type */ $this->argument('source'),
Loading history...
48
            $this->argument('date'),
0 ignored issues
show
Bug introduced by
It seems like $this->argument('date') can also be of type string[]; however, parameter $date of Orkhanahmadov\LaravelCur...r\Currencylayer::rate() does only seem to accept Carbon\Carbon|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

48
            /** @scrutinizer ignore-type */ $this->argument('date'),
Loading history...
49
            $this->argument('currencies')
50
        );
51
52
        $header = ['Currency', 'Value'];
53
        if (is_array($rates)) {
54
            $this->table($header, [array_keys($rates), array_values($rates)]);
55
        } else {
56
            $this->table($header, [$this->argument('currencies'), [$rates]]);
57
        }
58
    }
59
}
60