Completed
Push — master ( 4e8bc9...f46df8 )
by Tobias
13:01 queued 05:03
created

CatalogueWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A writeCatalogues() 0 14 2
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\Catalogue;
13
14
use Symfony\Component\Translation\MessageCatalogue;
15
use Symfony\Component\Translation\Writer\TranslationWriter;
16
use Translation\Bundle\Model\Configuration;
17
18
/**
19
 * Write catalogues back to disk.
20
 *
21
 * This should be considered as a "WriteToCache" service.
22
 *
23
 * @author Tobias Nyholm <[email protected]>
24
 */
25
final class CatalogueWriter
26
{
27
    /**
28
     * @var TranslationWriter
29
     */
30
    private $writer;
31
32
    /**
33
     * @var string
34
     */
35
    private $defaultLocale;
36
37
    /**
38
     * @param TranslationWriter $writer
39
     * @param string            $defaultLocale
40
     */
41 6
    public function __construct(
42
        TranslationWriter $writer,
43
        $defaultLocale
44
    ) {
45 6
        $this->writer = $writer;
46 6
        $this->defaultLocale = $defaultLocale;
47 6
    }
48
49
    /**
50
     * @param Configuration      $config
51
     * @param MessageCatalogue[] $catalogues
52
     */
53 1
    public function writeCatalogues(Configuration $config, array $catalogues)
54
    {
55 1
        foreach ($catalogues as $catalogue) {
56 1
            $this->writer->writeTranslations(
57 1
                $catalogue,
58 1
                $config->getOutputFormat(),
59
                [
60 1
                    'path' => $config->getOutputDir(),
61 1
                    'default_locale' => $this->defaultLocale,
62 1
                    'xliff_version' => $config->getXliffVersion(),
63
                ]
64 1
            );
65 1
        }
66 1
    }
67
}
68