Passed
Push — master ( 32ec39...4f5ed5 )
by Aranea
38:11 queued 23:10
created

ElectrumCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
dl 0
loc 77
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A author() 0 3 1
A __construct() 0 5 1
A handle() 0 8 2
A get_params() 0 17 4
1
<?php
2
3
namespace AraneaDev\Electrum\App\Console;
4
5
use Illuminate\Console\Command;
6
use AraneaDev\Electrum\Electrum;
7
8
/**
9
 * Class ElectrumCommand.
10
 */
11
class ElectrumCommand extends Command
12
{
13
    /** @var Electrum */
14
    protected $electrum;
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'electrum {method} {--address=} {--txid=} {--key=}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Wrapper for Electrum';
29
30
    /**
31
     * ElectrumCommand constructor.
32
     *
33
     * @param Electrum $electrum
34
     */
35
    public function __construct(Electrum $electrum)
36
    {
37
        $this->electrum = $electrum;
38
39
        parent::__construct();
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return mixed
46
     */
47
    public function handle()
48
    {
49
        $method = $this->argument('method');
50
51
        if (! method_exists($this, $method)) {
0 ignored issues
show
Bug introduced by
It seems like $method can also be of type array; however, parameter $method_name of method_exists() 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

51
        if (! method_exists($this, /** @scrutinizer ignore-type */ $method)) {
Loading history...
52
            $this->info(json_encode($this->electrum->sendRequest($method, $this->get_params())));
53
        } else {
54
            $this->$method();
55
        }
56
    }
57
58
    /**
59
     * Returns package author.
60
     *
61
     * @return void
62
     */
63
    public function author()
64
    {
65
        $this->info('Electrum for Laravel was written by Tim Schipper <[email protected]>');
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function get_params()
72
    {
73
        $params = [];
74
75
        if ($this->option('address')) {
76
            $params['address'] = $this->option('address');
77
        }
78
79
        if ($this->option('txid')) {
80
            $params['txid'] = $this->option('txid');
81
        }
82
83
        if ($this->option('key')) {
84
            $params['key'] = $this->option('key');
85
        }
86
87
        return $params;
88
    }
89
}
90