Translation::getKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace WebCMS\Entity;
4
5
use Doctrine\ORM\Mapping as orm;
6
7
/**
8
 * @orm\Entity
9
 * @orm\Table(uniqueConstraints={@orm\UniqueConstraint(name="hash_idx", columns={"hash"})})
10
 * @author Tomáš Voslař <tomas.voslar at webcook.cz>
11
 */
12
class Translation extends Entity
13
{
14
    /**
15
     * @orm\Column(name="`key`", type="text")
16
     * @var String
17
     */
18
    private $key;
19
20
    /**
21
     * @orm\Column(type="text")
22
     * @var String
23
     */
24
    private $translation;
25
26
    /**
27
     * @orm\ManyToOne(targetEntity="Language")
28
     * @orm\JoinColumn(name="language_id", referencedColumnName="id", onDelete="CASCADE")
29
     * @var Int
30
     */
31
    private $language;
32
33
    /**
34
     * @orm\Column(type="boolean")
35
     * @var Boolean
36
     */
37
    private $backend;
38
39
    /**
40
     * TODO unique=true
41
     * @orm\Column()
42
     * @var
43
     */
44
    private $hash;
45
46
    /**
47
     * @orm\Column(type="boolean")
48
     * @var Boolean
49
     */
50
    private $translated;
51
52
    public function getHash()
53
    {
54
        return $this->hash;
55
    }
56
57 41
    public function setHash()
58
    {
59 41
        $this->hash = sha1($this->getKey().$this->getLanguage()->getAbbr().$this->getBackend());
0 ignored issues
show
Bug introduced by
The method getAbbr cannot be called on $this->getLanguage() (of type integer).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
60 41
    }
61
62 41
    public function getKey()
63
    {
64 41
        return $this->key;
65
    }
66
67 1
    public function getTranslation()
68
    {
69 1
        return $this->translation;
70
    }
71
72 41
    public function getLanguage()
73
    {
74 41
        return $this->language;
75
    }
76
77 41
    public function getBackend()
78
    {
79 41
        return $this->backend;
80
    }
81
82 41
    public function setKey($key)
83
    {
84 41
        $this->key = $key;
85 41
    }
86
87 41
    public function setTranslation($translation)
88
    {
89 41
        $this->translation = $translation;
90 41
        $this->translated = $this->getTranslated();
91 41
    }
92
93 41
    public function setLanguage($language)
94
    {
95 41
        $this->language = $language;
96 41
    }
97
98 41
    public function setBackend($backend)
99
    {
100 41
        $this->backend = $backend;
101 41
    }
102
103 41
    public function getTranslated()
104
    {
105 41
        return md5($this->key) !== md5($this->translation);
106
    }
107
}
108