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