Completed
Push — master ( d80517...f6a7a5 )
by Oscar
04:52
created

YamlDictionary::toString()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 3
eloc 13
nc 2
nop 1
1
<?php
2
3
namespace Gettext\Generators;
4
5
use Gettext\Translations;
6
use Symfony\Component\Yaml\Dumper;
7
use Symfony\Component\Yaml\Parser;
8
9
class YamlDictionary extends Generator implements GeneratorInterface
10
{
11
    /**
12
     * {@parentDoc}.
13
     */
14
    public static function toString(Translations $translations)
15
    {
16
        $array = PhpArray::toArray($translations);
17
18
        //for a simple json translation dictionary, one domain is supported
19
        $values = current($array);
20
21
        // remove meta / header data
22
        if (array_key_exists('', $values)) {
23
            unset($values['']);
24
        }
25
26
        //map to a simple yml dictionary (no plurals)
27
        $yml    = new Dumper();
28
        $output = $yml->dump(
29
                array_map(
30
                    function ($val) {
31
                        return isset( $val[1] ) ? $val[1] : null;
32
                    },
33
                    $values
34
                ),
35
            1
36
        );
37
        
38
        return $output;
39
    }
40
}
41