Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

Model/Translation/TranslationGroup.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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