SubAccountCreateCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 5 1
A configure() 0 7 1
A execute() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Incapsula\Command;
6
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class SubAccountCreateCommand extends AbstractCommand
12
{
13
    /**
14
     * @var string
15
     */
16
    private $accountName;
17
18
    protected function configure(): void
19
    {
20
        parent::configure();
21
22
        $this
23
            ->setName('subaccount:create')
24
            ->addArgument('account-name', InputArgument::REQUIRED, 'sub account name')
25
        ;
26
    }
27
28
    protected function initialize(InputInterface $input, OutputInterface $output): void
29
    {
30
        parent::initialize($input, $output);
31
32
        $this->accountName = $input->getArgument('account-name');
0 ignored issues
show
Documentation Bug introduced by
It seems like $input->getArgument('account-name') can also be of type string[]. However, the property $accountName is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
33
    }
34
35
    protected function execute(InputInterface $input, OutputInterface $output): int
36
    {
37
        $this->client->accounts()->add($this->accountName);
38
39
        return 0;
40
    }
41
}
42