Conditions | 12 |
Paths | 28 |
Total Lines | 56 |
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 |
||
116 | function locale_dump() { |
||
117 | $strings = []; |
||
118 | |||
119 | $files = $this->jugaad_model->get_file_data(0, [ |
||
120 | 'files' => [ |
||
121 | 'type' => 'external', |
||
122 | 'path' => '**', |
||
123 | 'data' => [] |
||
124 | ] |
||
125 | ], $this->user); |
||
126 | |||
127 | $files = $files['files']; |
||
128 | |||
129 | foreach ($files as $file) { |
||
130 | $template_meta = $this->template_model->get_meta($file["template"]); |
||
131 | |||
132 | if ($template_meta === false) { |
||
133 | continue; |
||
134 | } |
||
135 | |||
136 | $translatable_types = ['text', 'longtext']; |
||
137 | |||
138 | foreach ($template_meta as $name => $meta) { |
||
139 | if (!(in_array($meta['type'], $translatable_types) |
||
140 | || ($meta['type'] == 'list' && in_array($meta['listType'], $translatable_types))) |
||
141 | ) { |
||
142 | unset($template_meta[$name]); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | $file_id = $this->jugaad_model->get_path_id(explode('/', $file['path'])); |
||
147 | $data = $this->jugaad_model->get_file_data($file_id, $template_meta, $this->user, true); |
||
148 | |||
149 | foreach ($data as $value) { |
||
150 | if (!$value) continue; |
||
151 | if (is_array($value)) { |
||
152 | foreach ($value as $val) { |
||
153 | $strings[] = $val; |
||
154 | } |
||
155 | } else { |
||
156 | $strings[] = $value; |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | |||
161 | header('Content-Type: text/plain; charset=UTF-8'); |
||
162 | |||
163 | echo "<?php |
||
164 | /** |
||
165 | * Save this code in src/locale/locale_dump.php |
||
166 | * After saving this scan src/ with poedit to start translating! |
||
167 | */ |
||
168 | |||
169 | "; |
||
170 | foreach ($strings as $string) { |
||
171 | echo '__("' . addslashes($string) . '");' . "\n"; |
||
172 | } |
||
176 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.