Conditions | 19 |
Paths | 272 |
Total Lines | 84 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
66 | protected function execute(InputInterface $input, OutputInterface $output) |
||
67 | { |
||
68 | $group = $input->getArgument('name'); |
||
69 | |||
70 | /** @var BaseConsumer[] $consumers */ |
||
71 | $consumers = []; |
||
72 | |||
73 | foreach ($this->consumers as $consumersByType) { |
||
74 | foreach ($consumersByType as $consumer) { |
||
75 | if (in_array($group, $consumer->getGroups(), true)) { |
||
76 | $consumers[] = $consumer; |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | if ([] === $consumers) { |
||
82 | throw new InvalidArgumentException(sprintf('No consumers with %s group', $group)); |
||
83 | } |
||
84 | |||
85 | $connectionName = $input->getOption('connection'); |
||
86 | $connectionServiceId = sprintf('old_sound_rabbit_mq.connection.%s', $connectionName); |
||
87 | if (false === $this->container->has($connectionServiceId)) { |
||
88 | throw new InvalidOptionException(sprintf('Rabbitmq connection %s is not defined', $connectionName)); |
||
89 | }; |
||
90 | |||
91 | |||
92 | if (defined('AMQP_WITHOUT_SIGNALS') === false) { |
||
93 | define('AMQP_WITHOUT_SIGNALS', $input->getOption('without-signals')); |
||
94 | } |
||
95 | |||
96 | if (!AMQP_WITHOUT_SIGNALS && extension_loaded('pcntl')) { |
||
97 | if (!function_exists('pcntl_signal')) { |
||
98 | throw new \BadFunctionCallException("Function 'pcntl_signal' is referenced in the php.ini 'disable_functions' and can't be called."); |
||
99 | } |
||
100 | |||
101 | $stopConsumer = function () use ($consumers) { |
||
102 | foreach ($consumers as $consumer) { |
||
103 | $consumer->forceStopConsumer(); |
||
104 | |||
105 | // Halt consumer if waiting for a new message from the queue |
||
106 | try { |
||
107 | $consumer->stopConsuming(); |
||
108 | } catch (AMQPTimeoutException $e) {} |
||
109 | } |
||
110 | }; |
||
111 | |||
112 | pcntl_signal(SIGTERM, $stopConsumer); |
||
113 | pcntl_signal(SIGINT, $stopConsumer); |
||
114 | pcntl_signal(SIGHUP, $stopConsumer); |
||
115 | } |
||
116 | |||
117 | if (defined('AMQP_DEBUG') === false) { |
||
118 | define('AMQP_DEBUG', (bool) $input->getOption('debug')); |
||
119 | } |
||
120 | |||
121 | |||
122 | |||
123 | /** @var AbstractConnection $connection */ |
||
124 | $connection = $this->container->get($connectionServiceId); |
||
125 | $channel = $connection->channel(); |
||
126 | |||
127 | $channel->basic_qos( |
||
128 | $input->getOption('qos-prefetch-size'), |
||
129 | $input->getOption('qos-prefetch-count'), |
||
130 | $input->getOption('qos-global') |
||
131 | ); |
||
132 | |||
133 | if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) { |
||
134 | foreach ($consumers as $i => $consumer) { |
||
135 | $consumer->setMemoryLimit($input->getOption('memory-limit')); |
||
136 | } |
||
137 | } |
||
138 | |||
139 | foreach ($consumers as $i => $consumer) { |
||
140 | $consumer->setChannel($channel); |
||
141 | $consumer->setConsumerTag(sprintf("PHPPROCESS_%s_%s_%s", gethostname(), getmypid(), $i)); |
||
142 | $consumer->setupConsumer(); |
||
143 | } |
||
144 | |||
145 | while (count($channel->callbacks)) { |
||
146 | $channel->wait(null, false, $input->getOption('timeout')); |
||
147 | } |
||
148 | |||
149 | return 0; |
||
150 | } |
||
151 | } |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..