| Conditions | 9 |
| Paths | 144 |
| Total Lines | 90 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 93 | public function handle() |
||
| 94 | { |
||
| 95 | $forceRecreate = $this->input->getOption('force'); |
||
| 96 | |||
| 97 | $hasErrors = false; |
||
| 98 | /** @var QueueEntity|ExchangeEntity $entity */ |
||
| 99 | foreach ($this->container->getPublishers() as $publisherName => $entity) { |
||
| 100 | try { |
||
| 101 | $this->createEntity($entity, 'publisher', $publisherName, $forceRecreate); |
||
| 102 | } catch (AMQPProtocolChannelException $e) { |
||
| 103 | $hasErrors = true; |
||
| 104 | $this->output->error( |
||
| 105 | sprintf( |
||
| 106 | "Could not create entity %s for publisher [%s], got:\n%s", |
||
| 107 | (string)$entity->getAliasName(), |
||
| 108 | (string)$publisherName, |
||
| 109 | (string)$e->getMessage() |
||
| 110 | ) |
||
| 111 | ); |
||
| 112 | $entity->reconnect(); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | /** @var QueueEntity|ExchangeEntity $entity */ |
||
| 117 | foreach ($this->container->getConsumers() as $publisherName => $entity) { |
||
| 118 | try { |
||
| 119 | $this->createEntity($entity, 'consumer', $publisherName, $forceRecreate); |
||
| 120 | } catch (AMQPProtocolChannelException $e) { |
||
| 121 | $hasErrors = true; |
||
| 122 | $this->output->error( |
||
| 123 | sprintf( |
||
| 124 | "Could not create entity %s for consumer [%s], got:\n%s", |
||
| 125 | (string)$entity->getAliasName(), |
||
| 126 | (string)$publisherName, |
||
| 127 | (string)$e->getMessage() |
||
| 128 | ) |
||
| 129 | ); |
||
| 130 | $entity->reconnect(); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | $this->output->block("Create binds"); |
||
| 135 | /** @var PublisherInterface $entity */ |
||
| 136 | foreach ($this->container->getPublishers() as $publisherName => $entity) { |
||
| 137 | try { |
||
| 138 | $entity->bind(); |
||
| 139 | $this->output->writeln( |
||
| 140 | sprintf( |
||
| 141 | "Created bind <info>%s</info> for publisher [<fg=yellow>%s</>]", |
||
| 142 | (string)$entity->getAliasName(), |
||
| 143 | (string)$publisherName |
||
| 144 | ) |
||
| 145 | ); |
||
| 146 | } catch (\Exception $e) { |
||
| 147 | $hasErrors = true; |
||
| 148 | $this->output->error( |
||
| 149 | sprintf( |
||
| 150 | "Could not bind entity %s for publisher [%s], got:\n%s", |
||
| 151 | (string)$entity->getAliasName(), |
||
| 152 | (string)$publisherName, |
||
| 153 | (string)$e->getMessage() |
||
| 154 | ) |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | /** @var ConsumerInterface $entity */ |
||
| 160 | foreach ($this->container->getConsumers() as $consumerAliasName => $entity) { |
||
| 161 | try { |
||
| 162 | $entity->bind(); |
||
| 163 | $this->output->writeln( |
||
| 164 | sprintf( |
||
| 165 | "Bind entity <info>%s</info> for consumer [<fg=yellow>%s</>]", |
||
| 166 | (string)$entity->getAliasName(), |
||
| 167 | (string)$consumerAliasName |
||
| 168 | ) |
||
| 169 | ); |
||
| 170 | } catch (\Exception $e) { |
||
| 171 | $hasErrors = true; |
||
| 172 | $this->output->error( |
||
| 173 | sprintf( |
||
| 174 | "Could not create bind %s for consumer [%s], got:\n%s", |
||
| 175 | (string)$entity->getAliasName(), |
||
| 176 | (string)$consumerAliasName, |
||
| 177 | (string)$e->getMessage() |
||
| 178 | ) |
||
| 179 | ); |
||
| 180 | } |
||
| 181 | } |
||
| 182 | return (int)$hasErrors; |
||
| 183 | } |
||
| 185 |