Completed
Push — master ( 6d6b78...3237ec )
by Tobias
04:15
created

Message::withMeta()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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\Common\Model;
13
14
final class Message implements MessageInterface
15
{
16
    /**
17
     * @var string
18
     *
19
     * The domain the message belongs to
20
     */
21
    private $domain;
22
23
    /**
24
     * @var string
25
     *
26
     * The key/phrase you write in the source code
27
     */
28
    private $key;
29
30
    /**
31
     * @var string
32
     *
33
     * The locale the translations is on
34
     */
35
    private $locale;
36
37
    /**
38
     * @var string
39
     *
40
     * The translated string. This is the preview of the message. Ie no placeholders is visible.
41
     */
42
    private $translation;
43
44
    /**
45
     * Key value array with metadata.
46
     *
47
     * @var array
48
     */
49
    private $meta = [];
50
51
    /**
52
     * @param string $key
53
     * @param string $domain
54
     * @param string $locale
55
     * @param string $translation
56
     * @param array  $meta
57
     */
58 3
    public function __construct($key, $domain = '', $locale = '', $translation = '', array $meta = [])
59
    {
60 3
        $this->key = $key;
61 3
        $this->domain = $domain;
62 3
        $this->locale = $locale;
63 3
        $this->translation = $translation;
64 3
        $this->meta = $meta;
65 3
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 2
    public function getDomain()
71
    {
72 2
        return $this->domain;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 2
    public function withDomain($domain)
79
    {
80 2
        $new = clone $this;
81 2
        $new->domain = $domain;
82
83 2
        return $new;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 2
    public function getKey()
90
    {
91 2
        return $this->key;
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 2
    public function getLocale()
98
    {
99 2
        return $this->locale;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105 2
    public function withLocale($locale)
106
    {
107 2
        $new = clone $this;
108 2
        $new->locale = $locale;
109
110 2
        return $new;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116 2
    public function getTranslation()
117
    {
118 2
        return $this->translation;
119
    }
120
121
    /**
122
     * {@inheritdoc}
123
     */
124 2
    public function withTranslation($translation)
125
    {
126 2
        $new = clone $this;
127 2
        $new->translation = $translation;
128
129 2
        return $new;
130
    }
131
132
    /**
133
     * {@inheritdoc}
134
     */
135 2
    public function getAllMeta()
136
    {
137 2
        return $this->meta;
138
    }
139
140
    /**
141
     * {@inheritdoc}
142
     */
143 2
    public function withMeta(array $meta)
144
    {
145 2
        $new = clone $this;
146 2
        $new->meta = $meta;
147
148 2
        return $new;
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154 2
    public function withAddedMeta($key, $value)
155
    {
156 2
        $new = clone $this;
157 2
        $new->meta[$key] = $value;
158
159 2
        return $new;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165 1
    public function getMeta($key, $default = null)
166
    {
167 1
        if (array_key_exists($key, $this->meta)) {
168 1
            return $this->meta[$key];
169
        }
170
171 1
        return $default;
172
    }
173
}
174