TranslationConverterCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 66
ccs 33
cts 33
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 12 1
A execute() 0 21 2
1
<?php
2
3
namespace Itkg\TranslationBundle\Command;
4
5
use Itkg\TranslationBundle\Extractor\TranslationExtractor;
6
use Itkg\TranslationBundle\Writer\MessageCatalogueWriter;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Filesystem\Filesystem;
12
use Symfony\Component\Finder\Finder;
13
use Symfony\Component\Translation\MessageCatalogue;
14
use Symfony\Component\Translation\Writer\TranslationWriter;
15
16
/**
17
 * Class TranslationConverterCommand
18
 */
19
class TranslationConverterCommand extends Command
20
{
21
    /**
22
     * @var TranslationExtractor
23
     */
24
    private $extractor;
25
26
    /**
27
     * @var MessageCatalogueWriter
28
     */
29
    private $writer;
30
31
    /**
32
     * @param TranslationExtractor   $extractor
33
     * @param MessageCatalogueWriter $writer
34
     * @param null|string            $name
35
     */
36 3
    public function __construct(TranslationExtractor $extractor, MessageCatalogueWriter $writer, $name = null)
37
    {
38 3
        $this->extractor = $extractor;
39 3
        $this->writer = $writer;
40
41 3
        parent::__construct($name);
42 3
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 3
    protected function configure()
48
    {
49 3
        $this
50 3
            ->setName('itkg:translation:convert')
51 3
            ->setDescription('Translation convert command from an input format to another format')
52 3
            ->setHelp('You must specify a path using the --path option.')
53 3
            ->addOption('path', null, InputOption::VALUE_REQUIRED, 'Specify a path of files')
54 3
            ->addOption('input', null, InputOption::VALUE_REQUIRED, 'Specifiy a input translation format')
55 3
            ->addOption('output', null, InputOption::VALUE_OPTIONAL, 'Specifiy an output translation format (default: xliff)')
56 3
            ->addOption('domain', null, InputOption::VALUE_OPTIONAL, 'All domains if not specified')
57 3
            ->addOption('output-path', null, InputOption::VALUE_OPTIONAL, 'Specify a path of output translations');
58 3
    }
59
60
    /**
61
     * {@inheritDoc}
62
     */
63 3
    protected function execute(InputInterface $input, OutputInterface $output)
64
    {
65 3
        $outputFormat = $input->getOption('output') ?: 'xliff';
66
67 3
        $messageCatalogues = $this->extractor->extract(
68 3
            $input->getOption('path'),
69 3
            $input->getOption('input'),
70 3
            $input->getOption('domain')
71 3
        );
72
73 3
        $this->writer->write($messageCatalogues, $outputFormat, $input->getOption('output-path'));
74
75 3
        $output->writeln(
76 3
            sprintf(
77 3
                'Conversion from %s to %s finished. Translations are available in %s',
78 3
                $input->getOption('input'),
79 3
                $input->getOption('output'),
80 3
                $input->getOption('path')
81 3
            )
82 3
        );
83 3
    }
84
}
85