Passed
Push — master ( 860d98...4489c1 )
by Orkhan
02:25
created

Command   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A output() 0 10 1
A prepareRows() 0 13 3
1
<?php
2
3
namespace Orkhanahmadov\LaravelCurrencylayer\Commands;
4
5
use Illuminate\Console\Command as BaseCommand;
6
use Symfony\Component\Console\Helper\Table;
7
8
abstract class Command extends BaseCommand
9
{
10
    /**
11
     * Renders console output.
12
     *
13
     * @param string $title
14
     * @param array $rows
15
     */
16
    protected function output(string $title, array $rows): void
17
    {
18
        $table = new Table($this->output);
19
20
        $table->setStyle('box-double')
21
            ->setHeaderTitle($title)
22
            ->setHeaders(['Currency', 'Rate'])
23
            ->addRows($rows);
24
25
        $table->render();
26
    }
27
28
    /**
29
     * Prepare table rows.
30
     *
31
     * @param array $currencies
32
     * @param array|float $rates
33
     *
34
     * @return array
35
     */
36
    protected function prepareRows(array $currencies, $rates): array
37
    {
38
        $rows = [];
39
40
        if (is_array($rates)) {
41
            foreach ($rates as $code => $rate) {
42
                $rows[] = [$code, $rate];
43
            }
44
        } else {
45
            $rows[] = [$currencies[0], $rates];
46
        }
47
48
        return $rows;
49
    }
50
}
51