Conditions | 26 |
Paths | 2401 |
Total Lines | 112 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
243 | public function exportTranslations($module, $excel = true, $onlyLang = [], $untranslated = false) |
||
244 | { |
||
245 | $fullLangPath = $this->getLangPath($module); |
||
246 | |||
247 | $translationFiles = glob($fullLangPath . '/*.yml'); |
||
248 | if ($translationFiles === false) { |
||
249 | $this->message("No yml"); |
||
250 | return; |
||
251 | } |
||
252 | |||
253 | // Collect messages in all lang |
||
254 | $allMessages = []; |
||
255 | $headers = ['key']; |
||
256 | $default = []; |
||
257 | $defaultFile = null; |
||
258 | $defaultLang = substr(i18n::get_locale(), 0, 2); |
||
259 | foreach ($translationFiles as $translationFile) { |
||
260 | $lang = pathinfo($translationFile, PATHINFO_FILENAME); |
||
261 | if ($lang == $defaultLang) { |
||
262 | $defaultFile = $translationFile; |
||
263 | } |
||
264 | if (!empty($onlyLang) && !in_array($lang, $onlyLang)) { |
||
265 | continue; |
||
266 | } |
||
267 | $headers[] = $lang; |
||
268 | $default[] = ''; |
||
269 | } |
||
270 | |||
271 | |||
272 | $masterMessages = []; |
||
273 | if ($untranslated) { |
||
274 | $reader = new YamlReader; |
||
275 | $masterMessages = $reader->read($defaultLang, $defaultFile); |
||
276 | } |
||
277 | |||
278 | $i = 0; |
||
279 | foreach ($translationFiles as $translationFile) { |
||
280 | $lang = pathinfo($translationFile, PATHINFO_FILENAME); |
||
281 | if (!empty($onlyLang) && !in_array($lang, $onlyLang)) { |
||
282 | continue; |
||
283 | } |
||
284 | $reader = new YamlReader; |
||
285 | $messages = $reader->read($lang, $translationFile); |
||
286 | |||
287 | foreach ($messages as $entityKey => $v) { |
||
288 | if ($untranslated) { |
||
289 | if (isset($masterMessages[$entityKey]) && $masterMessages[$entityKey] != $v) { |
||
290 | continue; |
||
291 | } |
||
292 | } |
||
293 | |||
294 | if (!isset($allMessages[$entityKey])) { |
||
295 | $allMessages[$entityKey] = $default; |
||
296 | } |
||
297 | // Plurals can be arrays and need to be converted |
||
298 | if (is_array($v)) { |
||
299 | $v = json_encode($v); |
||
300 | } |
||
301 | $allMessages[$entityKey][$i] = $v; |
||
302 | } |
||
303 | $i++; |
||
304 | } |
||
305 | // don't sort this will be mess up git when merging later |
||
306 | // ksort($allMessages); |
||
307 | if ($this->debug) { |
||
308 | Debug::show($allMessages); |
||
309 | } |
||
310 | |||
311 | // Write them to a file |
||
312 | if ($excel && class_exists(ExcelImportExport::class)) { |
||
313 | $ext = 'xlsx'; |
||
314 | $destinationFilename = str_replace('/lang', '/lang.' . $ext, $fullLangPath); |
||
315 | if ($this->debug) { |
||
316 | Debug::show("Debug mode enabled : no output will be sent to $destinationFilename"); |
||
317 | return; |
||
318 | } |
||
319 | if (is_file($destinationFilename)) { |
||
320 | unlink($destinationFilename); |
||
321 | } |
||
322 | // First row contains headers |
||
323 | $data = [$headers]; |
||
324 | // Add a row per lang |
||
325 | foreach ($allMessages as $key => $translations) { |
||
326 | array_unshift($translations, $key); |
||
327 | $data[] = $translations; |
||
328 | } |
||
329 | ExcelImportExport::arrayToFile($data, $destinationFilename); |
||
330 | } else { |
||
331 | $ext = 'csv'; |
||
332 | $destinationFilename = str_replace('/lang', '/lang.' . $ext, $fullLangPath); |
||
333 | if ($this->debug) { |
||
334 | Debug::show("Debug mode enabled : no output will be sent to $destinationFilename"); |
||
335 | return; |
||
336 | } |
||
337 | if (is_file($destinationFilename)) { |
||
338 | unlink($destinationFilename); |
||
339 | } |
||
340 | $fp = fopen($destinationFilename, 'w'); |
||
341 | if ($fp === false) { |
||
342 | throw new Exception("Failed to open stream"); |
||
343 | } |
||
344 | // UTF 8 fix |
||
345 | fprintf($fp, "\xEF\xBB\xBF"); |
||
346 | fputcsv($fp, $headers); |
||
347 | foreach ($allMessages as $key => $translations) { |
||
348 | array_unshift($translations, $key); |
||
349 | fputcsv($fp, $translations); |
||
350 | } |
||
351 | fclose($fp); |
||
352 | } |
||
353 | |||
354 | $this->message("Translations written to $destinationFilename"); |
||
355 | } |
||
362 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths