Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

ExportFile   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 31.91%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 2
dl 0
loc 113
ccs 15
cts 47
cp 0.3191
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fillArray() 0 7 2
A assignArrayByPath() 0 10 2
A getExtension() 0 4 1
A setExtension() 0 4 1
A getDomain() 0 4 1
A setDomain() 0 4 1
A getLocale() 0 4 1
A setLocale() 0 4 1
A getTranslations() 0 4 1
A setTranslations() 0 4 1
A getContent() 0 4 1
A setContent() 0 4 1
A addTranslation() 0 4 1
A getArray() 0 4 1
A setArray() 0 4 1
1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Model\Export;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Kunstmaan\TranslatorBundle\Entity\Translation;
7
8
/**
9
 * A representation of a translation export into a file
10
 */
11
class ExportFile
12
{
13
    private $extension;
14
15
    private $domain;
16
17
    private $locale;
18
19
    /**
20
     * ArrayCollection with keyword as key, text as value
21
     *
22
     * @var ArrayCollection
23
     */
24
    private $translations;
25
26
    /**
27
     * Translations converted into an array
28
     *
29
     * @var array
30
     */
31
    private $array = [];
32
33
    private $content = '';
34
35 1
    public function __construct()
36
    {
37 1
        $this->translations = new ArrayCollection();
38 1
    }
39
40
    public function fillArray()
41
    {
42
        foreach ($this->translations as $keyword => $text) {
43
            $this->assignArrayByPath($array, $keyword, $text);
44
            $this->array = array_merge_recursive($array, $this->array);
45
        }
46
    }
47
48
    public function assignArrayByPath(&$arr, $path, $value)
49
    {
50
        $keys = explode('.', $path);
51
52
        while ($key = array_shift($keys)) {
53
            $arr = &$arr[$key];
54
        }
55
56
        $arr = $value;
57
    }
58
59
    public function getExtension()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
60
    {
61
        return $this->extension;
62
    }
63
64 1
    public function setExtension($extension)
65
    {
66 1
        $this->extension = $extension;
67 1
    }
68
69
    public function getDomain()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
70
    {
71
        return $this->domain;
72
    }
73
74 1
    public function setDomain($domain)
75
    {
76 1
        $this->domain = $domain;
77 1
    }
78
79
    public function getLocale()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
80
    {
81
        return $this->locale;
82
    }
83
84 1
    public function setLocale($locale)
85
    {
86 1
        $this->locale = $locale;
87 1
    }
88
89
    public function getTranslations()
90
    {
91
        return $this->translations;
92
    }
93
94
    public function setTranslations($translations)
95
    {
96
        $this->translations = $translations;
97
    }
98
99
    public function getContent()
100
    {
101
        return $this->content;
102
    }
103
104
    public function setContent($content)
105
    {
106
        $this->content = $content;
107
    }
108
109 1
    public function addTranslation(Translation $translation)
110
    {
111 1
        $this->translations->set($translation->getKeyword(), $translation->getText());
112 1
    }
113
114
    public function getArray()
115
    {
116
        return $this->array;
117
    }
118
119
    public function setArray($array)
120
    {
121
        $this->array = $array;
122
    }
123
}
124