Completed
Push — master ( 46f2b5...868fd1 )
by Oscar
02:25
created

Jed::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Gettext\Generators;
4
5
use Gettext\Translations;
6
7
class Jed extends PhpArray implements GeneratorInterface
8
{
9
    /**
10
     * {@parentDoc}.
11
     */
12
    public static function toString(Translations $translations)
13
    {
14
        $array = static::toArray($translations);
15
16
        return json_encode($array);
17
    }
18
19
    /**
20
     * {@parentdoc}
21
     */
22 View Code Duplication
    protected static function buildArray(Translations $translations)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $array = array();
25
26
        $context_glue = "\004";
27
28
        foreach ($translations as $translation) {
29
            $key = ($translation->hasContext() ? $translation->getContext().$context_glue : '').$translation->getOriginal();
30
31
            if ($translation->hasPluralTranslation()) {
32
                $array[$key] = array_merge(array($translation->getTranslation()), $translation->getPluralTranslation());
33
            } else {
34
                $array[$key] = array($translation->getTranslation());
35
            }
36
        }
37
38
        return $array;
39
    }
40
}
41