| Conditions | 6 |
| Paths | 10 |
| Total Lines | 52 |
| Code Lines | 33 |
| 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 |
||
| 29 | public function createContainer(array $config) |
||
| 30 | { |
||
| 31 | $connections = $this->createConnections($config['connections']); |
||
| 32 | $exchanges = $this->createExchanges($config['exchanges'], $connections); |
||
| 33 | $queues = $this->createQueues($config['queues'], $connections); |
||
| 34 | |||
| 35 | $container = new Container(); |
||
| 36 | // create publishers |
||
| 37 | foreach ($config['publishers'] as $publisherAliasName => $publisherEntityBind) { |
||
| 38 | if ($exchanges->has($publisherEntityBind)) { |
||
| 39 | $entity = $exchanges->get($publisherEntityBind); |
||
| 40 | } elseif ($queues->has($publisherEntityBind)) { |
||
| 41 | $entity = $queues->get($publisherEntityBind); |
||
| 42 | } else { |
||
| 43 | throw new \RuntimeException( |
||
| 44 | sprintf( |
||
| 45 | "Cannot create publisher %s: no exchange or queue named %s defined!", |
||
| 46 | (string)$publisherAliasName, |
||
| 47 | (string)$publisherEntityBind |
||
| 48 | ) |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | $container->addPublisher( |
||
| 53 | $publisherAliasName, |
||
| 54 | $entity |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | |||
| 58 | foreach ($config['consumers'] as $consumerAliasName => $consumerDetails) { |
||
| 59 | $prefetchCount = $consumerDetails['prefetch_count']; |
||
| 60 | $messageProcessor = $consumerDetails['message_processor']; |
||
| 61 | |||
| 62 | if ($queues->has($consumerDetails['queue'])) { |
||
| 63 | /** @var QueueEntity $entity */ |
||
| 64 | $entity = $queues->get($consumerDetails['queue']); |
||
| 65 | } else { |
||
| 66 | throw new \RuntimeException( |
||
| 67 | sprintf( |
||
| 68 | "Cannot create consumer %s: no queue named %s defined!", |
||
| 69 | (string)$consumerAliasName, |
||
| 70 | (string)$consumerDetails['queue'] |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | $entity->setPrefetchCount($prefetchCount); |
||
| 76 | $entity->setMessageProcessor($messageProcessor); |
||
| 77 | $container->addConsumer($consumerAliasName, $entity); |
||
| 78 | } |
||
| 79 | |||
| 80 | return $container; |
||
| 81 | } |
||
| 167 |