Completed
Push — master ( c84ad1...740372 )
by Tobias
11:48 queued 09:34
created

CatalogueMessage   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 52.5%

Importance

Changes 0
Metric Value
wmc 16
lcom 2
cbo 2
dl 0
loc 138
ccs 21
cts 40
cp 0.525
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setMetadata() 0 4 1
A __toString() 0 4 1
A getKey() 0 4 1
A getDomain() 0 4 1
A getLocale() 0 4 1
A getMessage() 0 4 1
A getOtherTranslations() 0 8 1
A getSourceLocations() 0 8 2
A isNew() 0 8 2
A isObsolete() 0 8 2
A isApproved() 0 8 2
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 3
    public function __construct(CatalogueManager $catalogueManager, $locale, $domain, $key, $message)
61
    {
62 3
        $this->catalogueManager = $catalogueManager;
63 3
        $this->locale = $locale;
64 3
        $this->domain = $domain;
65 3
        $this->key = $key;
66 3
        $this->message = $message;
67 3
    }
68
69
    /**
70
     * @param null|Metadata $metadata
71
     */
72 3
    public function setMetadata(Metadata $metadata)
73
    {
74 3
        $this->metadata = $metadata;
75 3
    }
76
77
    public function __toString()
78
    {
79
        return $this->getMessage();
80
    }
81
82
    /**
83
     * @return string
84
     */
85 1
    public function getKey()
86
    {
87 1
        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
    public function getMessage()
110
    {
111
        return $this->message;
112
    }
113
114
    public function getOtherTranslations()
115
    {
116
        $translations = $this->catalogueManager->getTranslations($this->domain, $this->getKey());
117
118
        unset($translations[$this->locale]);
119
120
        return $translations;
121
    }
122
123
    public function getSourceLocations()
124
    {
125
        if (null === $this->metadata) {
126
            return [];
127
        }
128
129
        return $this->metadata->getSourceLocations();
130
    }
131
132 1
    public function isNew()
133
    {
134 1
        if (null === $this->metadata) {
135
            return false;
136
        }
137
138 1
        return $this->metadata->getState() === 'new';
139
    }
140
141 1
    public function isObsolete()
142
    {
143 1
        if (null === $this->metadata) {
144
            return false;
145
        }
146
147 1
        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