Completed
Push — master ( 1397e0...6a2cd6 )
by Sascha-Oliver
9s
created

XliffConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 34
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A contentToCatalogue() 0 8 1
A catalogueToContent() 0 6 1
1
<?php
2
3
namespace Translation\PlatformAdapter\PhraseApp\Bridge\Symfony;
4
5
use Symfony\Component\Translation\MessageCatalogue;
6
use Translation\SymfonyStorage\Dumper\XliffDumper;
7
use Translation\SymfonyStorage\Loader\XliffLoader;
8
9
/**
10
 * Utility class to convert between a MessageCatalogue and XLIFF file content.
11
 *
12
 * This class can be removed when https://github.com/php-translation/symfony-storage/pull/8 is accepted and merged
13
 */
14
final class XliffConverter
15
{
16
    /**
17
     * Create a catalogue from the contents of a XLIFF file.
18
     *
19
     * @param string $content
20
     * @param string $locale
21
     * @param string $domain
22
     *
23
     * @return MessageCatalogue
24
     */
25
    public static function contentToCatalogue($content, $locale, $domain)
26
    {
27
        $loader = new XliffLoader();
28
        $catalogue = new MessageCatalogue($locale);
29
        $loader->extractFromContent($content, $catalogue, $domain);
30
31
        return $catalogue;
32
    }
33
34
    /**
35
     * @param MessageCatalogue $catalogue
36
     * @param string           $domain
37
     * @param array            $options
38
     *
39
     * @return string
40
     */
41
    public static function catalogueToContent(MessageCatalogue $catalogue, $domain, array $options = [])
42
    {
43
        $dumper = new XliffDumper();
44
45
        return $dumper->getFormattedCatalogue($catalogue, $domain, $options);
46
    }
47
}
48