Completed
Push — master ( 41d47b...c28fef )
by James
10s
created

FetchCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 67.57%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 61
ccs 25
cts 37
cp 0.6757
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B configure() 0 26 1
A execute() 0 19 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Command;
5
6
use BrowscapPHP\BrowscapUpdater;
7
use BrowscapPHP\Helper\IniLoader;
8
use BrowscapPHP\Helper\LoggerHelper;
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\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * Command to fetch a browscap ini file from the remote host and store the content in a local file
17
 */
18
class FetchCommand extends Command
19
{
20
    /**
21
     * @var string
22
     */
23
    private $defaultIniFile;
24
25 1
    public function __construct(string $defaultIniFile)
26
    {
27 1
        $this->defaultIniFile = $defaultIniFile;
28
29 1
        parent::__construct();
30 1
    }
31
32 1
    protected function configure() : void
33
    {
34
        $this
35 1
            ->setName('browscap:fetch')
36 1
            ->setDescription('Fetches an updated INI file for Browscap.')
37 1
            ->addArgument(
38 1
                'file',
39 1
                InputArgument::OPTIONAL,
40 1
                'browscap.ini file',
41 1
                $this->defaultIniFile
42
            )
43 1
            ->addOption(
44 1
                'remote-file',
45 1
                'r',
46 1
                InputOption::VALUE_OPTIONAL,
47 1
                'browscap.ini file to download from remote location (possible values are: ' . IniLoader::PHP_INI_LITE
48 1
                . ', ' . IniLoader::PHP_INI . ', ' . IniLoader::PHP_INI_FULL . ')',
49 1
                IniLoader::PHP_INI
50
            )
51 1
            ->addOption(
52 1
                'debug',
53 1
                'd',
54 1
                InputOption::VALUE_NONE,
55 1
                'Should the debug mode entered?'
56
            );
57 1
    }
58
59
    protected function execute(InputInterface $input, OutputInterface $output) : void
60
    {
61
        $loggerHelper = new LoggerHelper();
62
        $logger = $loggerHelper->create($input->getOption('debug'));
63
64
        $file = $input->getArgument('file');
65
        if (! $file) {
66
            $file = $this->defaultIniFile;
67
        }
68
69
        $logger->info('started fetching remote file');
70
71
        $browscap = new BrowscapUpdater();
72
73
        $browscap->setLogger($logger);
74
        $browscap->fetch($file, $input->getOption('remote-file'));
75
76
        $logger->info('finished fetching remote file');
77
    }
78
}
79