Completed
Push — master ( 75ac31...11edf4 )
by Tobias
08:15 queued 06:58
created

XliffDumper::dumpXliff1()   C

Complexity

Conditions 12
Paths 36

Size

Total Lines 78
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 0
Metric Value
dl 0
loc 78
ccs 0
cts 58
cp 0
rs 5.1746
c 0
b 0
f 0
cc 12
eloc 48
nc 36
nop 4
crap 156

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\SymfonyStorage\Dumper;
13
14
use Nyholm\NSA;
15
use Symfony\Component\Translation\Dumper\XliffFileDumper;
16
use Symfony\Component\Translation\MessageCatalogue;
17
use Symfony\Component\Translation\Exception\InvalidArgumentException;
18
use Translation\SymfonyStorage\Dumper\Port\SymfonyPort;
19
20
/**
21
 * XliffFileDumper generates xliff files from a message catalogue.
22
 *
23
 * This class provides support for both SF2.7 and SF3.0+
24
 *
25
 * @author Tobias Nyholm <[email protected]>
26
 * @author Michel Salib <[email protected]>
27
 */
28
final class XliffDumper extends XliffFileDumper
29
{
30
    /**
31
     * @var SymfonyPort|null
32
     */
33
    private $sfPort;
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = [])
39
    {
40 3
        $xliffVersion = '1.2';
41 3
        if (array_key_exists('xliff_version', $options)) {
42 3
            $xliffVersion = $options['xliff_version'];
43 3
        }
44
45 3
        if (array_key_exists('default_locale', $options)) {
46
            $defaultLocale = $options['default_locale'];
47
        } else {
48 3
            $defaultLocale = \Locale::getDefault();
49
        }
50
51 3
        if ('1.2' === $xliffVersion) {
52 1
            if (method_exists($this, 'dumpXliff1')) {
53 1
                return NSA::invokeMethod($this, 'dumpXliff1', $defaultLocale, $messages, $domain, $options);
54
            } else {
55
                // Symfony 2.7
56
                return $this->format($messages, $domain);
0 ignored issues
show
Bug introduced by
The method format() does not exist on Translation\SymfonyStorage\Dumper\XliffDumper. Did you maybe mean formatCatalogue()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
57
            }
58
        }
59
60 2
        if ('2.0' === $xliffVersion) {
61 2
            if (null === $this->sfPort) {
62 2
                $this->sfPort = new SymfonyPort();
63 2
            }
64
65 2
            return $this->sfPort->dumpXliff2($defaultLocale, $messages, $domain, $options);
66
        }
67
68
        throw new InvalidArgumentException(
69
            sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion)
70 1
        );
71
    }
72
}
73