| Conditions | 9 |
| Paths | 256 |
| Total Lines | 56 |
| Code Lines | 37 |
| 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 |
||
| 71 | final protected function mergeSettings(TaisiyaStyle $io): void |
||
| 72 | { |
||
| 73 | $io->isVerbose() && $io->writeln('Merge settings into one file'); |
||
| 74 | |||
| 75 | $uname = php_uname('n'); |
||
| 76 | $files = []; |
||
| 77 | |||
| 78 | $finder = Finder::create() |
||
| 79 | ->in(TAISIYA_ROOT) |
||
| 80 | ->path('app/config') |
||
| 81 | ->files() |
||
| 82 | ->name('/\.settings\.default\.php$/'); |
||
| 83 | |||
| 84 | foreach ($finder as $file) { |
||
| 85 | $files[] = $file->getPathname(); |
||
| 86 | } |
||
| 87 | |||
| 88 | $finder = Finder::create() |
||
| 89 | ->in(TAISIYA_ROOT) |
||
| 90 | ->path('app/config') |
||
| 91 | ->files() |
||
| 92 | ->name('/\.settings\.local\.php$/'); |
||
| 93 | |||
| 94 | foreach ($finder as $file) { |
||
| 95 | $files[] = $file->getPathname(); |
||
| 96 | } |
||
| 97 | |||
| 98 | $finder = Finder::create() |
||
| 99 | ->in(TAISIYA_ROOT) |
||
| 100 | ->path('app/config') |
||
| 101 | ->files() |
||
| 102 | ->name('/\.settings\.'.preg_quote($uname, '/').'\.local\.php$/'); |
||
| 103 | |||
| 104 | foreach ($finder as $file) { |
||
| 105 | $files[] = $file->getPathname(); |
||
| 106 | } |
||
| 107 | |||
| 108 | $files[] = TAISIYA_ROOT.'/app/config/settings.default.php'; |
||
| 109 | if (file_exists(TAISIYA_ROOT.'/app/config/settings.local.php')) { |
||
| 110 | $files[] = TAISIYA_ROOT.'/app/config/settings.local.php'; |
||
| 111 | } |
||
| 112 | if (file_exists(TAISIYA_ROOT.'/app/config/settings.'.$uname.'.local.php')) { |
||
| 113 | $files[] = TAISIYA_ROOT.'/app/config/settings.'.$uname.'.local.php'; |
||
| 114 | } |
||
| 115 | |||
| 116 | $settings = []; |
||
| 117 | foreach ($files as $file) { |
||
| 118 | $settings = array_merge_recursive($settings, require $file); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (!file_put_contents(TAISIYA_ROOT.'/app/config/settings.php', "<?php\n\nreturn ".var_export($settings, true).";\n")) { |
||
| 122 | throw new RuntimeException('Couldn\'t write to the file '.TAISIYA_ROOT.'/app/config/settings.php'); |
||
| 123 | } else { |
||
| 124 | $io->writeln(' - writed to <info>app/config/settings.php</info>'); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 |