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