Conditions | 19 |
Paths | 272 |
Total Lines | 83 |
Code Lines | 43 |
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 |
||
69 | protected function execute(InputInterface $input, OutputInterface $output) |
||
70 | { |
||
71 | $group = $input->getArgument('name'); |
||
72 | |||
73 | /** @var BaseConsumer[] $consumers */ |
||
74 | $consumers = []; |
||
75 | |||
76 | foreach ($this->consumers as $consumersByType) { |
||
77 | foreach ($consumersByType as $consumer) { |
||
78 | if (in_array($group, $consumer->getGroups(), true)) { |
||
79 | $consumers[] = $consumer; |
||
80 | } |
||
81 | } |
||
82 | } |
||
83 | |||
84 | if ([] === $consumers) { |
||
85 | throw new InvalidArgumentException(sprintf('No consumers with %s group', $group)); |
||
86 | } |
||
87 | |||
88 | $connectionName = $input->getOption('connection'); |
||
89 | $connectionServiceId = sprintf('old_sound_rabbit_mq.connection.%s', $connectionName); |
||
90 | if (false === $this->container->has($connectionServiceId)) { |
||
91 | throw new InvalidOptionException(sprintf('Rabbitmq connection %s is not defined', $connectionName)); |
||
92 | }; |
||
93 | |||
94 | |||
95 | if (defined('AMQP_WITHOUT_SIGNALS') === false) { |
||
96 | define('AMQP_WITHOUT_SIGNALS', $input->getOption('without-signals')); |
||
97 | } |
||
98 | |||
99 | if (!AMQP_WITHOUT_SIGNALS && extension_loaded('pcntl')) { |
||
100 | if (!function_exists('pcntl_signal')) { |
||
101 | throw new \BadFunctionCallException("Function 'pcntl_signal' is referenced in the php.ini 'disable_functions' and can't be called."); |
||
102 | } |
||
103 | |||
104 | $stopConsumer = function () use ($consumers) { |
||
105 | foreach ($consumers as $consumer) { |
||
106 | $consumer->forceStopConsumer(); |
||
107 | |||
108 | // Halt consumer if waiting for a new message from the queue |
||
109 | try { |
||
110 | $consumer->stopConsuming(); |
||
111 | } catch (AMQPTimeoutException $e) {} |
||
112 | } |
||
113 | }; |
||
114 | |||
115 | pcntl_signal(SIGTERM, $stopConsumer); |
||
116 | pcntl_signal(SIGINT, $stopConsumer); |
||
117 | } |
||
118 | |||
119 | if (defined('AMQP_DEBUG') === false) { |
||
120 | define('AMQP_DEBUG', (bool) $input->getOption('debug')); |
||
121 | } |
||
122 | |||
123 | |||
124 | |||
125 | /** @var AbstractConnection $connection */ |
||
126 | $connection = $this->container->get($connectionServiceId); |
||
127 | $channel = $connection->channel(); |
||
128 | |||
129 | $channel->basic_qos( |
||
130 | $input->getOption('qos-prefetch-size'), |
||
131 | $input->getOption('qos-prefetch-count'), |
||
132 | $input->getOption('qos-global') |
||
133 | ); |
||
134 | |||
135 | if (!is_null($input->getOption('memory-limit')) && ctype_digit((string) $input->getOption('memory-limit')) && $input->getOption('memory-limit') > 0) { |
||
136 | foreach ($consumers as $i => $consumer) { |
||
137 | $consumer->setMemoryLimit($input->getOption('memory-limit')); |
||
138 | } |
||
139 | } |
||
140 | |||
141 | foreach ($consumers as $i => $consumer) { |
||
142 | $consumer->setChannel($channel); |
||
143 | $consumer->setConsumerTag(sprintf("PHPPROCESS_%s_%s_%s", gethostname(), getmypid(), $i)); |
||
144 | $consumer->setupConsumer(); |
||
145 | } |
||
146 | |||
147 | while (count($channel->callbacks)) { |
||
148 | $channel->wait(null, false, $input->getOption('timeout')); |
||
149 | } |
||
150 | |||
151 | return 0; |
||
152 | } |
||
153 | } |
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..