| Conditions | 10 |
| Paths | 21 |
| Total Lines | 54 |
| Code Lines | 30 |
| 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 |
||
| 32 | public function generate() |
||
| 33 | { |
||
| 34 | if (!is_dir($this->config['path']) && !mkdir($this->config['path'], 0755, true)) { |
||
| 35 | throw new \RuntimeException(sprintf( |
||
| 36 | 'path "%s" could not be created', |
||
| 37 | $this->config['path'] |
||
| 38 | )); |
||
| 39 | } |
||
| 40 | |||
| 41 | // create directory structure |
||
| 42 | foreach (['worker' => true, 'conf.d' => true, 'logs' => false] as $directory => $cleanup) { |
||
| 43 | $path = sprintf('%s/%s', $this->config['path'], $directory); |
||
| 44 | |||
| 45 | if (!is_dir($path)) { |
||
| 46 | mkdir($path, 0755); |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($cleanup) { |
||
| 50 | $this->cleanup($path); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | file_put_contents( |
||
| 55 | sprintf('%s/%s', $this->config['path'], 'supervisord.conf'), |
||
| 56 | $this->templating->render( |
||
| 57 | 'RabbitMqManagerBundle:Supervisor:supervisor.conf.twig', [ |
||
| 58 | 'path' => $this->config['path'], |
||
| 59 | ] |
||
| 60 | ) |
||
| 61 | ); |
||
| 62 | |||
| 63 | foreach (['consumers', 'rpc_servers'] as $type) { |
||
| 64 | foreach ($this->config[$type] as $name => $consumer) { |
||
| 65 | if (!isset($consumer['worker']['queue']['routing'])) { |
||
| 66 | $this->writeConfig( |
||
| 67 | sprintf('%s_%s', $type, $name), |
||
| 68 | $this->config['path'], |
||
| 69 | $consumer |
||
| 70 | ); |
||
| 71 | |||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | foreach ($consumer['worker']['queue']['routing'] as $index => $route) { |
||
| 76 | $this->writeConfig( |
||
| 77 | sprintf('%s_%s_%s', $type, $name, $index), |
||
| 78 | $this->config['path'], |
||
| 79 | $consumer, |
||
| 80 | $route |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 149 |