Completed
Push — master ( a970ae...d902d2 )
by Oscar
01:58
created

Csv::toString()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 11
c 1
b 1
f 0
nc 3
nop 2
dl 0
loc 20
rs 9.4285
1
<?php
2
3
namespace Gettext\Generators;
4
5
use Gettext\Translations;
6
use Gettext\Utils\DictionaryTrait;
7
8
/**
9
 * Class to export translations to csv
10
 */
11
class Csv extends Generator implements GeneratorInterface
12
{
13
    /**
14
     * {@parentDoc}.
15
     */
16
    public static function toString(Translations $translations, array $options = [])
17
    {
18
        $handle = fopen('php://memory', 'w');
19
20
        foreach ($translations as $translation) {
21
            $line = [$translation->getContext(), $translation->getOriginal(), $translation->getTranslation()];
22
            
23
            if ($translation->hasPluralTranslations()) {
24
                $line = array_merge($line, $translation->getPluralTranslations());
25
            }
26
27
            fputcsv($handle, $line);
28
        }
29
30
        rewind($handle);
31
        $csv = stream_get_contents($handle);
32
        fclose($handle);
33
34
        return $csv;
35
    }
36
}
37