UntranslatedMessageExporter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 7
c 2
b 1
f 0
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exportPoString() 0 9 2
A __construct() 0 3 1
1
<?php
2
3
namespace Printful\GettextCms;
4
5
use Gettext\Generators\Po;
6
7
/**
8
 * Export untranslated messages to a .po file contents that can be saved for translating
9
 */
10
class UntranslatedMessageExporter
11
{
12
    /** @var MessageStorage */
13
    private $storage;
14
15 9
    public function __construct(MessageStorage $storage)
16
    {
17 9
        $this->storage = $storage;
18 9
    }
19
20
    /**
21
     * Export untranslated messages to a PO file string.
22
     * If no messages exist, empty string is returned.
23
     *
24
     * @param string $locale
25
     * @param string $domain
26
     * @return string PO file contents or empty string if nothing to export
27
     */
28 8
    public function exportPoString(string $locale, string $domain): string
29
    {
30 8
        $translations = $this->storage->getRequiresTranslating($locale, $domain);
31
32 8
        if (!$translations->count()) {
33 3
            return '';
34
        }
35
36 5
        return Po::toString($translations);
37
    }
38
}