Completed
Push — master ( 740372...dc5b6e )
by Tobias
10:09
created

CatalogueMessage::getMessage()   A

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
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\Bundle\Model;
13
14
use Translation\Bundle\Catalogue\CatalogueManager;
15
16
/**
17
 * A message representation for CatalogueManager.
18
 *
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
final class CatalogueMessage
22
{
23
    /**
24
     * @var CatalogueManager
25
     */
26
    private $catalogueManager;
27
28
    /**
29
     * @var string
30
     */
31
    private $key;
32
33
    /**
34
     * @var string
35
     */
36
    private $message;
37
38
    /**
39
     * @var string
40
     */
41
    private $domain;
42
43
    /**
44
     * @var string
45
     */
46
    private $locale;
47
48
    /**
49
     * @var Metadata|null
50
     */
51
    private $metadata;
52
53
    /**
54
     * @param CatalogueManager $catalogueManager
55
     * @param string           $locale
56
     * @param string           $domain
57
     * @param string           $key
58
     * @param string           $message
59
     */
60 4
    public function __construct(CatalogueManager $catalogueManager, $locale, $domain, $key, $message)
61
    {
62 4
        $this->catalogueManager = $catalogueManager;
63 4
        $this->locale = $locale;
64 4
        $this->domain = $domain;
65 4
        $this->key = $key;
66 4
        $this->message = $message;
67 4
    }
68
69
    /**
70
     * @param null|Metadata $metadata
71
     */
72 4
    public function setMetadata(Metadata $metadata)
73
    {
74 4
        $this->metadata = $metadata;
75 4
    }
76
77
    public function __toString()
78
    {
79
        return $this->getMessage();
80
    }
81
82
    /**
83
     * @return string
84
     */
85 2
    public function getKey()
86
    {
87 2
        return $this->key;
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getDomain()
94
    {
95
        return $this->domain;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    public function getLocale()
102
    {
103
        return $this->locale;
104
    }
105
106
    /**
107
     * @return string
108
     */
109 1
    public function getMessage()
110
    {
111 1
        return $this->message;
112
    }
113
114 1
    public function getOtherTranslations()
115
    {
116 1
        $translations = $this->catalogueManager->getTranslations($this->domain, $this->getKey());
117
118 1
        unset($translations[$this->locale]);
119
120 1
        return $translations;
121
    }
122
123 1
    public function getSourceLocations()
124
    {
125 1
        if (null === $this->metadata) {
126
            return [];
127
        }
128
129 1
        return $this->metadata->getSourceLocations();
130
    }
131
132 2
    public function isNew()
133
    {
134 2
        if (null === $this->metadata) {
135
            return false;
136
        }
137
138 2
        return $this->metadata->getState() === 'new';
139
    }
140
141 2
    public function isObsolete()
142
    {
143 2
        if (null === $this->metadata) {
144
            return false;
145
        }
146
147 2
        return $this->metadata->getState() === 'obsolete';
148
    }
149
150 1
    public function isApproved()
151
    {
152 1
        if (null === $this->metadata) {
153
            return false;
154
        }
155
156 1
        return $this->metadata->isApproved();
157
    }
158
}
159