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

TranslateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
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