| Conditions | 4 |
| Paths | 6 |
| Total Lines | 29 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | public static function toString(Translations $translations) |
||
| 13 | { |
||
| 14 | $array = PhpArray::toArray($translations); |
||
| 15 | |||
| 16 | //for a simple json translation dictionary, one domain is supported |
||
| 17 | $values = current($array); |
||
| 18 | |||
| 19 | // remove meta / header data |
||
| 20 | if (array_key_exists('', $values)) { |
||
| 21 | unset($values['']); |
||
| 22 | } |
||
| 23 | |||
| 24 | $tmpFile = tempnam(sys_get_temp_dir(), 'gettext_'); |
||
| 25 | $handle = fopen($tmpFile, 'w'); |
||
| 26 | |||
| 27 | //map to a simple csv dictionary (no plurals) |
||
| 28 | foreach ($values as $original => $translated) { |
||
|
|
|||
| 29 | if (!isset($translated[1])) { |
||
| 30 | $translated[1] = ''; |
||
| 31 | } |
||
| 32 | fputcsv($handle, array($original, $translated[1])); |
||
| 33 | } |
||
| 34 | |||
| 35 | fclose($handle); |
||
| 36 | $csv = file_get_contents($tmpFile); |
||
| 37 | unlink($tmpFile); |
||
| 38 | |||
| 39 | return $csv; |
||
| 40 | } |
||
| 41 | } |
||
| 42 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.