CreateTranslationCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 3
c 1
b 1
f 1
lcom 1
cbo 5
dl 0
loc 71
ccs 42
cts 42
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 27 1
B execute() 0 31 2
1
<?php
2
/**
3
 * @namespace Asm\TranslationLoaderBundle\Command
4
 */
5
namespace Asm\TranslationLoaderBundle\Command;
6
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class DumpTranslationFiles
13
 *
14
 * @package Asm\TranslationLoaderBundle\Command
15
 * @author marc aschmann <[email protected]>
16
 * @uses Symfony\Component\Console\Input\InputArgument
17
 * @uses Symfony\Component\Console\Input\InputInterface
18
 * @uses Symfony\Component\Console\Input\InputOption
19
 * @uses Symfony\Component\Console\Output\OutputInterface
20
 */
21
class CreateTranslationCommand extends BaseTranslationCommand
22
{
23
    /**
24
     * command configuration
25
     */
26 6
    protected function configure()
27
    {
28 6
        $this
29 6
            ->setName('asm:translations:create')
30 6
            ->setDescription('add new translation to db')
31 6
            ->addArgument(
32 6
                'key',
33 6
                InputArgument::REQUIRED,
34
                'translation key'
35 6
            )
36 6
            ->addArgument(
37 6
                'locale',
38 6
                InputArgument::REQUIRED,
39
                'locale (e.g. en, en_US, ...)'
40 6
            )
41 6
            ->addArgument(
42 6
                'translation',
43 6
                InputArgument::REQUIRED,
44
                'translation text'
45 6
            )
46 6
            ->addArgument(
47 6
                'domain',
48 6
                InputArgument::OPTIONAL,
49 6
                'specific message domain, default "messages"',
50
                'messages'
51 6
            );
52 6
    }
53
54
55
    /**
56
     * @param InputInterface $input
57
     * @param OutputInterface $output
58
     * @return int|null|void
59
     */
60 2
    protected function execute(InputInterface $input, OutputInterface $output)
61
    {
62 2
        $domain = $input->getArgument('domain');
63 2
        $action = 'updated';
64
65 2
        $translationManager = $this->getTranslationManager();
66
67 2
        $translation = $translationManager->findTranslationBy(
68
            array(
69 2
                'transKey'      => $input->getArgument('key'),
70 2
                'transLocale'   => $input->getArgument('locale'),
71 2
                'messageDomain' => $domain,
72
            )
73 2
        );
74
75
        // insert if no entry exists
76 2
        if (!$translation) {
77 1
            $translation = $translationManager->createTranslation();
78 1
            $translation->setTransKey($input->getArgument('key'));
79 1
            $translation->setTransLocale($input->getArgument('locale'));
80 1
            $translation->setMessageDomain($domain);
81
82 1
            $action = 'created';
83 1
        }
84
85
        // and in either case we want to add a message :-)
86 2
        $translation->setTranslation($input->getArgument('translation'));
87
88 2
        $output->writeln('<info>' . $action . ' translation</info>');
89 2
        $translationManager->updateTranslation($translation);
90 2
    }
91
}
92