CsvDictionary   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 3
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 21 3
1
<?php
2
3
namespace Gettext\Extractors;
4
5
use Gettext\Translations;
6
use Gettext\Utils\HeadersExtractorTrait;
7
use Gettext\Utils\CsvTrait;
8
9
/**
10
 * Class to get gettext strings from csv.
11
 */
12
class CsvDictionary extends Extractor implements ExtractorInterface
13
{
14
    use HeadersExtractorTrait;
15
    use CsvTrait;
16
17
    public static $options = [
18
        'delimiter' => ",",
19
        'enclosure' => '"',
20
        'escape_char' => "\\"
21
    ];
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public static function fromString($string, Translations $translations, array $options = [])
27
    {
28
        $options += static::$options;
29
        $handle = fopen('php://memory', 'w');
30
31
        fputs($handle, $string);
32
        rewind($handle);
33
34
        while ($row = self::fgetcsv($handle, $options)) {
35
            list($original, $translation) = $row + ['', ''];
36
37
            if ($original === '') {
38
                self::extractHeaders($translation, $translations);
39
                continue;
40
            }
41
42
            $translations->insert(null, $original)->setTranslation($translation);
43
        }
44
45
        fclose($handle);
46
    }
47
}
48