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

Jed   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 52.94 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 0 6 1
A buildArray() 18 18 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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