ChangeKeysCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Bytesfield\KeyManager\Commands;
4
5
use Bytesfield\KeyManager\KeyManagerInterface;
6
use Illuminate\Console\Command;
7
8 View Code Duplication
class ChangeKeysCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'client:changekey {clientId}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Command to change client public/private keys';
23
24
    /**
25
     * The KeyManagerInterface.
26
     *
27
     * @var KeyManagerInterface
28
     */
29
    private $manager;
30
31
    /**
32
     * @param KeyManagerInterface $manager
33
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
34
     */
35
    public function __construct(KeyManagerInterface $manager)
36
    {
37
        $this->manager = $manager;
38
39
        parent::__construct();
40
    }
41
42
    /**
43
     * Execute the console command.
44
     *
45
     * @return void
46
     */
47
    public function handle(): void
48
    {
49
        $key = $this->manager->changeKeys($this->argument('clientId'));
0 ignored issues
show
Documentation introduced by
$this->argument('clientId') is of type string|array|null, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        $this->info($key->getData()->status == true ? 'Success' : 'Failed');
51
52
        $this->info($key->getData()->message);
53
54
        $this->info($key->getData()->data->key);
55
    }
56
}
57