Completed
Push — master ( b33aa2...131cc8 )
by Sean
13s queued 11s
created

SetStaticCacheModeCommand::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Incapsula\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
class SetStaticCacheModeCommand extends AbstractCommand
10
{
11
    /**
12
     * @var string
13
     */
14
    private $siteId;
15
16
    /**
17
     * @var string
18
     */
19
    private $certificatePath;
0 ignored issues
show
introduced by
The private property $certificatePath is not used, and could be removed.
Loading history...
20
21
    /**
22
     * @var string
23
     */
24
    private $privateKeyPath;
0 ignored issues
show
introduced by
The private property $privateKeyPath is not used, and could be removed.
Loading history...
25
26
    protected function configure()
27
    {
28
        parent::configure();
29
30
        $this
31
            ->setName('StaticCacheMode:set')
32
            ->addArgument('site-id', InputArgument::REQUIRED, 'Site ID')
33
            ->setDescription('Ensure a site is in static caching header mode')
34
        ;
35
    }
36
37
    /**
38
     * @param InputInterface  $input
39
     * @param OutputInterface $output
40
     */
41
    protected function initialize(InputInterface $input, OutputInterface $output)
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
    }
47
48
    /**
49
     * @param InputInterface  $input
50
     * @param OutputInterface $output
51
     *
52
     * @return int
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $return_val = $this->client->sites()->setStaticCacheMode(
57
            $this->siteId
58
        );
59
60
        return $return_val;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $return_val returns the type array which is incompatible with the documented return type integer.
Loading history...
61
    }
62
}
63