Passed
Pull Request — master (#352)
by Rustam
04:14
created

TranslateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 26
ccs 0
cts 13
cp 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 7 1
A configure() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Command\Translation;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Yiisoft\Translator\TranslatorInterface;
12
13
final class TranslateCommand extends Command
14
{
15
    protected static $defaultName = 'translator/translate';
16
    protected static $defaultDescription = 'Translates a message';
17
18
    private TranslatorInterface $translator;
19
20
    public function __construct(TranslatorInterface $translator)
21
    {
22
        $this->translator = $translator;
23
        parent::__construct();
24
    }
25
26
    protected function configure()
27
    {
28
        $this->addArgument('message', InputArgument::REQUIRED, 'Message that will be translated.');
29
        $this->addArgument('locale', InputArgument::OPTIONAL, 'Translation locale.');
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $message = $input->getArgument('message');
35
        $locale = $input->getArgument('locale');
36
37
        $output->writeln($this->translator->translate($message, [], null, $locale));
38
        return 0;
39
    }
40
}
41