Issues (9)

src/Command/CustomCertificateUploadCommand.php (3 issues)

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 CustomCertificateUploadCommand extends AbstractCommand
12
{
13
    /**
14
     * @var string
15
     */
16
    private $siteId;
17
18
    /**
19
     * @var string
20
     */
21
    private $certificatePath;
22
23
    /**
24
     * @var string
25
     */
26
    private $privateKeyPath;
27
28
    protected function configure(): void
29
    {
30
        parent::configure();
31
32
        $this
33
            ->setName('customcertificate:upload')
34
            ->addArgument('site-id', InputArgument::REQUIRED, 'Site ID')
35
            ->addArgument('certificate-path', InputArgument::REQUIRED, 'Certificate path')
36
            ->addArgument('private-key-path', InputArgument::REQUIRED, 'Private key path')
37
            ->setDescription('Upload a custom certificate to a site')
38
        ;
39
    }
40
41
    protected function initialize(InputInterface $input, OutputInterface $output): void
42
    {
43
        parent::initialize($input, $output);
44
45
        $this->siteId = $input->getArgument('site-id');
0 ignored issues
show
Documentation Bug introduced by
It seems like $input->getArgument('site-id') can also be of type string[]. However, the property $siteId 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...
46
        $this->certificatePath = $input->getArgument('certificate-path');
0 ignored issues
show
Documentation Bug introduced by
It seems like $input->getArgument('certificate-path') can also be of type string[]. However, the property $certificatePath 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...
47
        $this->privateKeyPath = $input->getArgument('private-key-path');
0 ignored issues
show
Documentation Bug introduced by
It seems like $input->getArgument('private-key-path') can also be of type string[]. However, the property $privateKeyPath 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...
48
    }
49
50
    protected function execute(InputInterface $input, OutputInterface $output): int
51
    {
52
        $this->client->sites()->uploadCustomCertificate(
53
            $this->siteId,
54
            file_get_contents($this->certificatePath),
55
            file_get_contents($this->privateKeyPath)
56
        );
57
58
        return 0;
59
    }
60
}
61