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

Jed::buildArray()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 18
rs 9.2
cc 4
eloc 10
nc 5
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