CatalogueMessage   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Test Coverage

Coverage 52.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 114
ccs 21
cts 40
cp 0.525
rs 10
wmc 16

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getOtherTranslations() 0 7 1
A getMessage() 0 3 1
A getLocale() 0 3 1
A getDomain() 0 3 1
A setMetadata() 0 3 1
A isApproved() 0 7 2
A isNew() 0 7 2
A __toString() 0 3 1
A getKey() 0 3 1
A isObsolete() 0 7 2
A getSourceLocations() 0 7 2
A __construct() 0 7 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 3
    public function __construct(CatalogueManager $catalogueManager, string $locale, string $domain, string $key, string $message)
54
    {
55 3
        $this->catalogueManager = $catalogueManager;
56 3
        $this->locale = $locale;
57 3
        $this->domain = $domain;
58 3
        $this->key = $key;
59 3
        $this->message = $message;
60 3
    }
61
62 3
    public function setMetadata(Metadata $metadata): void
63
    {
64 3
        $this->metadata = $metadata;
65 3
    }
66
67
    public function __toString(): string
68
    {
69
        return $this->getMessage();
70
    }
71
72 1
    public function getKey(): string
73
    {
74 1
        return $this->key;
75
    }
76
77
    public function getDomain(): string
78
    {
79
        return $this->domain;
80
    }
81
82
    public function getLocale(): string
83
    {
84
        return $this->locale;
85
    }
86
87
    public function getMessage(): string
88
    {
89
        return $this->message;
90
    }
91
92
    public function getOtherTranslations(): array
93
    {
94
        $translations = $this->catalogueManager->getTranslations($this->domain, $this->getKey());
95
96
        unset($translations[$this->locale]);
97
98
        return $translations;
99
    }
100
101
    public function getSourceLocations(): array
102
    {
103
        if (null === $this->metadata) {
104
            return [];
105
        }
106
107
        return $this->metadata->getSourceLocations();
108
    }
109
110 1
    public function isNew(): bool
111
    {
112 1
        if (null === $this->metadata) {
113
            return false;
114
        }
115
116 1
        return 'new' === $this->metadata->getState();
117
    }
118
119 1
    public function isObsolete(): bool
120
    {
121 1
        if (null === $this->metadata) {
122
            return false;
123
        }
124
125 1
        return 'obsolete' === $this->metadata->getState();
126
    }
127
128 1
    public function isApproved(): bool
129
    {
130 1
        if (null === $this->metadata) {
131
            return false;
132
        }
133
134 1
        return $this->metadata->isApproved();
135
    }
136
}
137