Completed
Push — master ( 2b75e8...156030 )
by Faiz
02:20
created

TranslationAddCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 8
dl 0
loc 60
ccs 0
cts 47
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 13 1
A execute() 0 15 2
A allTranslations() 0 5 1
A translationTable() 0 9 1
1
<?php
2
3
namespace FaizShukri\Quran\Commands;
4
5
use FaizShukri\Quran\Supports\Config;
6
use FaizShukri\Quran\Supports\Downloader;
7
use FaizShukri\Quran\TanzilTranslations;
8
use FaizShukri\Quran\Repositories\Source\XMLRepository;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
use Symfony\Component\Console\Helper\Table;
14
15
class TranslationAddCommand extends Command
16
{
17
    private $source;
18
19
    private $config;
20
21
    public function __construct()
22
    {
23
        parent::__construct();
24
        $this->config = new Config;
25
        $this->source = new XMLRepository;
26
        $this->source->setConfig($this->config);
27
    }
28
29
    protected function configure()
30
    {
31
        $this
32
            ->setName('translation:add')
33
            ->setDescription('Add new translation')
34
            ->addArgument(
35
                'translation',
36
                InputArgument::OPTIONAL,
37
                'Translation to add'
38
            )
39
            ->addUsage('ms.basmeih')
40
        ;
41
    }
42
43
    protected function execute(InputInterface $input, OutputInterface $output)
44
    {
45
        $translation = $input->getArgument('translation');
46
47
        if($translation === null){
48
            $this->translationTable($output, $this->allTranslations());
49
            $output->writeln("<info>Please specify a </info><comment>translation ID</comment><info>. You can refer to the table above.</info>\n");
50
        } else {
51
            $this->config->customTranslations($translation);
52
            // dump($this->config->get('translations'));
53
            $dw = new Downloader($this->config);
54
            $dw->sync();
55
            $output->writeln("<info>$translation</info> has been added successfully.\n");
56
        }
57
    }
58
59
    private function allTranslations()
60
    {
61
        $tanzil = new TanzilTranslations;
62
        return $tanzil->get();
63
    }
64
65
    private function translationTable($output, $translations)
66
    {
67
        $table = new Table($output);
68
        $table
69
            ->setHeaders(['ID', 'Language', 'Name', 'Translator'])
70
            ->setRows($translations)
71
        ;
72
        $table->render();
73
    }
74
}
75