Conditions | 10 |
Paths | 12 |
Total Lines | 38 |
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 |
||
37 | public function generate(): string |
||
38 | { |
||
39 | // Init the variable |
||
40 | $config = ''; |
||
41 | |||
42 | // Basic parameters first |
||
43 | foreach ($this->config->getParameters() as $key => $value) { |
||
44 | $config .= $key . ($value !== '' ? ' ' . $value : '') . "\n"; |
||
45 | } |
||
46 | |||
47 | // Get all what need for normal work |
||
48 | $pushes = $this->config->getPushes(); |
||
49 | $routes = $this->config->getRoutes(); |
||
50 | $certs = $this->config->getCerts(); |
||
51 | |||
52 | // If we have routes or pushes in lists then generate it |
||
53 | if (count($pushes) || count($routes)) { |
||
54 | $config .= "\n### Networking\n"; |
||
55 | foreach ($routes as $route) { |
||
56 | $config .= 'route ' . $route . "\n"; |
||
57 | } |
||
58 | foreach ($pushes as $push) { |
||
59 | $config .= 'push "' . $push . "\"\n"; |
||
60 | } |
||
61 | } |
||
62 | |||
63 | // Certs should be below everything, due embedded keys and certificates |
||
64 | if (count($certs) > 0) { |
||
65 | $config .= "\n### Certificates\n"; |
||
66 | foreach ($this->config->getCerts() as $key => $value) { |
||
67 | $config .= isset($value['content']) |
||
68 | ? "<$key>\n{$value['content']}\n</$key>\n" |
||
69 | : "$key {$value['path']}\n"; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return $config; |
||
74 | } |
||
75 | } |
||
76 |