CreateClientCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 63
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 18 2
1
<?php
2
3
namespace Bytesfield\KeyManager\Commands;
4
5
use Bytesfield\KeyManager\KeyManagerInterface;
6
use Illuminate\Console\Command;
7
8
class CreateClientCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'client:create {name} {type} {status=active}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Command to create client with API keys';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
28
     */
29
30
    /**
31
     * The KeyManagerInterface.
32
     *
33
     * @var KeyManagerInterface
34
     */
35
    private $manager;
36
37
    /**
38
     * @param KeyManagerInterface $manager
39
     */
40
    public function __construct(KeyManagerInterface $manager)
41
    {
42
        $this->manager = $manager;
43
44
        parent::__construct();
45
    }
46
47
    /**
48
     * Execute the console command.
49
     *
50
     * @return void
51
     */
52
    public function handle(): void
53
    {
54
        $name = $this->argument('name');
55
56
        $type = $this->argument('type');
57
58
        $status = $this->argument('status');
59
60
        $client = $this->manager->createClient($name, $type, $status);
0 ignored issues
show
Bug introduced by
It seems like $name defined by $this->argument('name') on line 54 can also be of type array or null; however, Bytesfield\KeyManager\Ke...terface::createClient() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $type defined by $this->argument('type') on line 56 can also be of type array or null; however, Bytesfield\KeyManager\Ke...terface::createClient() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug introduced by
It seems like $status defined by $this->argument('status') on line 58 can also be of type array or null; however, Bytesfield\KeyManager\Ke...terface::createClient() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
61
62
        $this->info($client->getData()->status == true ? 'Success' : 'Failed');
63
64
        $this->info($client->getData()->message);
65
66
        $key = $this->manager->getPrivateKey($client->getData()->data->id);
67
68
        $this->info('client key: '.$key->getData()->data->key);
69
    }
70
}
71