Completed
Push — master ( b453a3...b1e9d6 )
by Ruud
40:05 queued 27:14
created

TranslationGroup::hasTranslation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Model\Translation;
4
5
use Kunstmaan\TranslatorBundle\Entity\Translation;
6
7
/**
8
 * Groups all translations for all languages specified by a key
9
 **/
10
class TranslationGroup
11
{
12
    /**
13
     * Translation ID
14
     */
15
    private $id;
16
17
    /**
18
     * All translations for a specific key (Kunstmaan\TranslatorBundle\Model\Translation\Translation)
19
     *
20
     * @var Doctrine\Common\Collections\ArrayCollection
21
     **/
22
    private $translations;
23
24
    /**
25
     * Translation identifier
26
     *
27
     * @var string
28
     **/
29
    private $keyword;
30
31
    /**
32
     * The domain name of this group
33
     *
34
     **/
35
    private $domain;
36
37 3
    public function __construct()
38
    {
39 3
        $this->translations = new \Doctrine\Common\Collections\ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Kunstmaan\Transla...ctions\ArrayCollection> of property $translations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40 3
    }
41
42 3
    public function hasTranslation($locale)
43
    {
44 3
        if (count($this->translations) <= 0) {
45 3
            return false;
46
        }
47
48 3
        if ($this->getTranslationByLocale($locale) !== null) {
49 3
            return true;
50
        }
51
52 2
        return false;
53
    }
54
55 3
    public function getTranslationByLocale($locale)
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...
56
    {
57 3
        if (count($this->translations) <= 0) {
58
            return null;
59
        }
60
61 3
        foreach ($this->translations as $translation) {
62 3
            if (strtolower($translation->getLocale()) == strtolower($locale)) {
63 3
                return $translation;
64
            }
65
        }
66
67 2
        return null;
68
    }
69
70
    public function getTranslationTextByLocale($locale)
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...
71
    {
72
        $translation = $this->getTranslationByLocale($locale);
73
74
        return is_null($translation) ? null : $translation->getText();
75
    }
76
77
    public function addTranslation(Translation $translation)
78
    {
79
        $translation->setTranslationId($this->getId());
80
        $this->translations->add($translation);
81
    }
82
83
    public function getTranslations()
84
    {
85
        return $this->translations;
86
    }
87
88 3
    public function setTranslations($translations)
89
    {
90 3
        foreach ($translations as $translation) {
91 3
            $translation->setTranslationId($this->getId());
92
        }
93 3
        $this->translations = $translations;
94 3
    }
95
96
    /**
97
     * @param mixed $id
98
     */
99 3
    public function setId($id)
100
    {
101 3
        $this->id = $id;
102 3
    }
103
104
    /**
105
     * @return mixed
106
     */
107 3
    public function getId()
108
    {
109 3
        return $this->id;
110
    }
111
112 3
    public function getKeyword()
113
    {
114 3
        return $this->keyword;
115
    }
116
117 3
    public function setKeyword($keyword)
118
    {
119 3
        $this->keyword = $keyword;
120 3
    }
121
122 3
    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...
123
    {
124 3
        return $this->domain;
125
    }
126
127 3
    public function setDomain($domain)
128
    {
129 3
        $this->domain = $domain;
130 3
    }
131
}
132