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
|
|||
39 | $this->resourcePattern = $input->getArgument('resource-pattern'); |
||
0 ignored issues
–
show
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 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;
}
![]() |
|||
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 |
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 theid
property of an instance of theAccount
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.