Completed
Push — master ( 91576d...2659cb )
by Oscar
02:19
created

CsvDictionary::fromString()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
cc 3
eloc 11
c 5
b 1
f 0
nc 4
nop 3
dl 0
loc 21
rs 9.3142
1
<?php
2
3
namespace Gettext\Extractors;
4
5
use Gettext\Translations;
6
7
/**
8
 * Class to get gettext strings from plain json.
9
 */
10
class CsvDictionary extends Extractor implements ExtractorInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public static function fromString($string, Translations $translations, array $options = [])
16
    {
17
        $handle = fopen('php://memory', 'w');
18
19
        fputs($handle, $string);
20
        rewind($handle);
21
22
        $entries = [];
23
24
        while ($row = fgetcsv($handle)) {
25
            $entries[$row[0]] = $row[1];
26
        }
27
28
        fclose($handle);
29
30
        foreach ($entries as $original => $translation) {
31
            $translations->insert(null, $original)->setTranslation($translation);
32
        }
33
34
        return $translations;
35
    }
36
}
37