Passed
Push — master ( c56ef2...593f48 )
by Mārtiņš
02:01
created

UntranslatedMessageExporter::exportPoString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
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
}