| Conditions | 21 |
| Paths | 421 |
| Total Lines | 93 |
| Code Lines | 62 |
| 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 |
||
| 232 | public function exportTranslations($module, $excel = true, $onlyLang = []) |
||
| 233 | { |
||
| 234 | $fullLangPath = $this->getLangPath($module); |
||
| 235 | |||
| 236 | $translationFiles = glob($fullLangPath . '/*.yml'); |
||
| 237 | if ($translationFiles === false) { |
||
| 238 | $this->message("No yml"); |
||
| 239 | return; |
||
| 240 | } |
||
| 241 | |||
| 242 | // Collect messages in all lang |
||
| 243 | $allMessages = []; |
||
| 244 | $headers = ['key']; |
||
| 245 | $default = []; |
||
| 246 | foreach ($translationFiles as $translationFile) { |
||
| 247 | $lang = pathinfo($translationFile, PATHINFO_FILENAME); |
||
| 248 | if (!empty($onlyLang) && !in_array($lang, $onlyLang)) { |
||
| 249 | continue; |
||
| 250 | } |
||
| 251 | $headers[] = $lang; |
||
| 252 | $default[] = ''; |
||
| 253 | } |
||
| 254 | |||
| 255 | $i = 0; |
||
| 256 | foreach ($translationFiles as $translationFile) { |
||
| 257 | $lang = pathinfo($translationFile, PATHINFO_FILENAME); |
||
| 258 | if (!empty($onlyLang) && !in_array($lang, $onlyLang)) { |
||
| 259 | continue; |
||
| 260 | } |
||
| 261 | $reader = new YamlReader; |
||
| 262 | $messages = $reader->read($lang, $translationFile); |
||
| 263 | |||
| 264 | foreach ($messages as $entityKey => $v) { |
||
| 265 | if (!isset($allMessages[$entityKey])) { |
||
| 266 | $allMessages[$entityKey] = $default; |
||
| 267 | } |
||
| 268 | // Plurals can be arrays and need to be converted |
||
| 269 | if (is_array($v)) { |
||
| 270 | $v = json_encode($v); |
||
| 271 | } |
||
| 272 | $allMessages[$entityKey][$i] = $v; |
||
| 273 | } |
||
| 274 | $i++; |
||
| 275 | } |
||
| 276 | ksort($allMessages); |
||
| 277 | if ($this->debug) { |
||
| 278 | Debug::show($allMessages); |
||
| 279 | } |
||
| 280 | |||
| 281 | // Write them to a file |
||
| 282 | if ($excel && class_exists(ExcelImportExport::class)) { |
||
| 283 | $ext = 'xlsx'; |
||
| 284 | $destinationFilename = str_replace('/lang', '/lang.' . $ext, $fullLangPath); |
||
| 285 | if ($this->debug) { |
||
| 286 | Debug::show("Debug mode enabled : no output will be sent to $destinationFilename"); |
||
| 287 | return; |
||
| 288 | } |
||
| 289 | if (is_file($destinationFilename)) { |
||
| 290 | unlink($destinationFilename); |
||
| 291 | } |
||
| 292 | // First row contains headers |
||
| 293 | $data = [$headers]; |
||
| 294 | // Add a row per lang |
||
| 295 | foreach ($allMessages as $key => $translations) { |
||
| 296 | array_unshift($translations, $key); |
||
| 297 | $data[] = $translations; |
||
| 298 | } |
||
| 299 | ExcelImportExport::arrayToFile($data, $destinationFilename); |
||
| 300 | } else { |
||
| 301 | $ext = 'csv'; |
||
| 302 | $destinationFilename = str_replace('/lang', '/lang.' . $ext, $fullLangPath); |
||
| 303 | if ($this->debug) { |
||
| 304 | Debug::show("Debug mode enabled : no output will be sent to $destinationFilename"); |
||
| 305 | return; |
||
| 306 | } |
||
| 307 | if (is_file($destinationFilename)) { |
||
| 308 | unlink($destinationFilename); |
||
| 309 | } |
||
| 310 | $fp = fopen($destinationFilename, 'w'); |
||
| 311 | if ($fp === false) { |
||
| 312 | throw new Exception("Failed to open stream"); |
||
| 313 | } |
||
| 314 | // UTF 8 fix |
||
| 315 | fprintf($fp, "\xEF\xBB\xBF"); |
||
| 316 | fputcsv($fp, $headers); |
||
| 317 | foreach ($allMessages as $key => $translations) { |
||
| 318 | array_unshift($translations, $key); |
||
| 319 | fputcsv($fp, $translations); |
||
| 320 | } |
||
| 321 | fclose($fp); |
||
| 322 | } |
||
| 323 | |||
| 324 | $this->message("Translations written to $destinationFilename"); |
||
| 325 | } |
||
| 332 |
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