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

YamlDictionary   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B toString() 0 26 3
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