PurgeSiteCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 1
A configure() 0 9 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 PurgeSiteCommand extends AbstractCommand
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $siteId;
17
    /**
18
     * @var string
19
     */
20
    protected $resourcePattern;
21
22
    protected function configure(): void
23
    {
24
        parent::configure();
25
26
        $this
27
            ->setName('site:purge')
28
            ->setDescription('Purge URLs from a given site id')
29
            ->addArgument('site-id', InputArgument::REQUIRED, 'incapsula id of site to purge')
30
            ->addArgument('resource-pattern', InputArgument::OPTIONAL, 'string to match in the URL to be purged', '')
31
        ;
32
    }
33
34
    protected function initialize(InputInterface $input, OutputInterface $output): void
35
    {
36
        parent::initialize($input, $output);
37
38
        $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...
39
        $this->resourcePattern = $input->getArgument('resource-pattern');
0 ignored issues
show
Documentation Bug introduced by
It seems like $input->getArgument('resource-pattern') can also be of type string[]. However, the property $resourcePattern 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...
40
    }
41
42
    protected function execute(InputInterface $input, OutputInterface $output): int
43
    {
44
        $this->client->sites()->purgeCache($this->siteId, $this->resourcePattern);
45
46
        return 0;
47
    }
48
}
49