Passed
Push — master ( f73d2a...b6f14a )
by f
14:52
created

DriversCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 5
A configure() 0 5 1
1
<?php
2
3
namespace wapmorgan\UnifiedArchive\Commands;
4
5
use Symfony\Component\Console\Helper\FormatterHelper;
6
use Symfony\Component\Console\Helper\Table;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use wapmorgan\UnifiedArchive\Drivers\BasicDriver;
10
use wapmorgan\UnifiedArchive\Formats;
11
12
class DriversCommand extends BaseCommand
13
{
14
    protected static $defaultName = 'system:drivers';
15
16
    protected function configure()
17
    {
18
        $this
19
            ->setDescription('Lists supported drivers for different formats and their installation status in system')
20
            ->setHelp('Lists supported drivers for different formats and their installation status in system. You need to manually install any of them.')
21
        ;
22
    }
23
24
    public function execute(InputInterface $input, OutputInterface $output)
25
    {
26
        $notInstalled = [];
27
        /** @var FormatterHelper $formatter */
28
        $formatter = $this->getHelper('formatter');
29
30
        /** @var BasicDriver $driverClass */
31
        foreach (Formats::$drivers as $driverClass) {
32
            $description = $driverClass::getDescription();
33
            $install = $driverClass::getInstallationInstruction();
34
            if (!empty($install)) {
35
                $notInstalled[] = [$driverClass, $description, $install];
36
            } else {
37
                $output->writeln($formatter->formatSection($driverClass, $description) . ': ' . implode(', ', $driverClass::getSupportedFormats()));
38
            }
39
        }
40
41
        if (!empty($notInstalled)) {
42
            foreach ($notInstalled as $data) {
43
                $output->writeln($formatter->formatSection($data[0], $data[1] . ': ' . implode(', ', $data[0]::getSupportedFormats()), 'error'));
44
                $output->writeln($formatter->formatSection($data[0], $data[2], 'comment'));
45
            }
46
        }
47
    }
48
}
49