Completed
Pull Request — master (#88)
by
unknown
64:04
created

XlfExport   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A export() 0 16 4
1
<?php
2
3
namespace ONGR\TranslationsBundle\Translation\Export;
4
5
use Symfony\Component\Translation\Dumper\XliffFileDumper;
6
use Symfony\Component\Translation\MessageCatalogue;
7
8
/**
9
 * Class XlfExport for dumping translations to yml file.
10
 */
11
class XlfExport implements ExporterInterface
12
{
13
    /**
14
     * Export translations in to the given file.
15
     *
16
     * @param string           $file
17
     * @param MessageCatalogue $translations
18
     * @param string           $domain
19
     *
20
     * @return bool
21
     */
22
    public function export($file, MessageCatalogue $translations, $domain)
23
    {
24
        if (pathinfo($file, PATHINFO_EXTENSION) === 'xlf') {
25
            $xlfDumper = new XliffFileDumper();
26
            try {
27
                $xlfContent = $xlfDumper->formatCatalogue($translations, $domain);
28
                if ($xlfContent !== false) {
29
                    return (file_put_contents($file, $xlfContent) !== false);
30
                }
31
            } catch (\Exception $e) {
32
                return false;
33
            }
34
        }
35
36
        return false;
37
    }
38
39
}