Skip to content

Commit 590e531

Browse files
committed
fix phpstan warnings
1 parent 441efe2 commit 590e531

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

Command/AnonConsumerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ protected function configure()
1010

1111
$this->setName('rabbitmq:anon-consumer');
1212
$this->setDescription('Executes an anonymous consumer');
13-
$this->getDefinition()->getOption('messages')->setDefault(1);
13+
$this->getDefinition()->getOption('messages')->setDefault('1');
1414
$this->getDefinition()->getOption('route')->setDefault('#');
1515

1616
}

Command/BaseConsumerCommand.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ abstract class BaseConsumerCommand extends BaseRabbitMqCommand
1313
{
1414
protected $consumer;
1515

16+
/** @var int */
1617
protected $amount;
1718

1819
abstract protected function getConsumerService();
@@ -41,14 +42,22 @@ protected function configure()
4142

4243
$this
4344
->addArgument('name', InputArgument::REQUIRED, 'Consumer Name')
44-
->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', 0)
45+
->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', '0')
4546
->addOption('route', 'r', InputOption::VALUE_OPTIONAL, 'Routing Key', '')
4647
->addOption('memory-limit', 'l', InputOption::VALUE_OPTIONAL, 'Allowed memory for this process (MB)', null)
4748
->addOption('debug', 'd', InputOption::VALUE_NONE, 'Enable Debugging')
4849
->addOption('without-signals', 'w', InputOption::VALUE_NONE, 'Disable catching of system signals')
4950
;
5051
}
5152

53+
protected function initialize(InputInterface $input, OutputInterface $output)
54+
{
55+
$this->amount = (int)$input->getOption('messages');
56+
if (0 > $this->amount) {
57+
throw new \InvalidArgumentException("The -m option should be null or greater than 0");
58+
}
59+
}
60+
5261
/**
5362
* Executes the current command.
5463
*
@@ -80,23 +89,21 @@ protected function execute(InputInterface $input, OutputInterface $output)
8089
define('AMQP_DEBUG', (bool) $input->getOption('debug'));
8190
}
8291

83-
$this->amount = $input->getOption('messages');
84-
85-
if (0 > (int) $this->amount) {
86-
throw new \InvalidArgumentException("The -m option should be null or greater than 0");
87-
}
8892
$this->initConsumer($input);
8993

9094
return $this->consumer->consume($this->amount);
9195
}
9296

93-
protected function initConsumer($input)
97+
protected function initConsumer(InputInterface $input)
9498
{
9599
$this->consumer = $this->getContainer()
96100
->get(sprintf($this->getConsumerService(), $input->getArgument('name')));
97101

98-
if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) {
99-
$this->consumer->setMemoryLimit($input->getOption('memory-limit'));
102+
if ($input->hasOption('memory-limit')) {
103+
$memoryLimit = (int)$input->getOption('memory-limit');
104+
if ($memoryLimit > 0) {
105+
$this->consumer->setMemoryLimit($memoryLimit);
106+
}
100107
}
101108
$this->consumer->setRoutingKey($input->getOption('route'));
102109
}

Command/BaseRabbitMqCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ public function getContainer()
2828
{
2929
return $this->container;
3030
}
31+
32+
3133
}

Command/BatchConsumerCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function configure()
3636
$this
3737
->setName('rabbitmq:batch:consumer')
3838
->addArgument('name', InputArgument::REQUIRED, 'Consumer Name')
39-
->addOption('batches', 'b', InputOption::VALUE_OPTIONAL, 'Number of batches to consume', 0)
39+
->addOption('batches', 'b', InputOption::VALUE_OPTIONAL, 'Number of batches to consume', '0')
4040
->addOption('route', 'r', InputOption::VALUE_OPTIONAL, 'Routing Key', '')
4141
->addOption('memory-limit', 'l', InputOption::VALUE_OPTIONAL, 'Allowed memory for this process', null)
4242
->addOption('debug', 'd', InputOption::VALUE_NONE, 'Enable Debugging')
@@ -75,8 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7575
define('AMQP_DEBUG', (bool) $input->getOption('debug'));
7676
}
7777

78-
$batchAmountTarget = (int) $input->getOption('batches');
79-
78+
$batchAmountTarget = (int)$input->getOption('batches');
8079
if (0 > $batchAmountTarget) {
8180
throw new \InvalidArgumentException("The -b option should be greater than 0");
8281
}

Command/RpcServerCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected function configure()
1717
->setName('rabbitmq:rpc-server')
1818
->setDescription('Start an RPC server')
1919
->addArgument('name', InputArgument::REQUIRED, 'Server Name')
20-
->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', 0)
20+
->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', '0')
2121
->addOption('debug', 'd', InputOption::VALUE_OPTIONAL, 'Debug mode', false)
2222
;
2323
}
@@ -35,9 +35,9 @@ protected function configure()
3535
protected function execute(InputInterface $input, OutputInterface $output)
3636
{
3737
define('AMQP_DEBUG', (bool) $input->getOption('debug'));
38-
$amount = $input->getOption('messages');
38+
$amount = (int)$input->getOption('messages');
3939

40-
if (0 > (int) $amount) {
40+
if (0 > $amount) {
4141
throw new \InvalidArgumentException("The -m option should be null or greater than 0");
4242
}
4343

0 commit comments

Comments
 (0)