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