Completed
Push — master ( 7014bb...a38bcf )
by James
15s
created

FetchCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Command;
5
6
use BrowscapPHP\BrowscapUpdater;
7
use BrowscapPHP\Helper\IniLoaderInterface;
8
use BrowscapPHP\Helper\LoggerHelper;
9
use Doctrine\Common\Cache\FilesystemCache;
10
use Roave\DoctrineSimpleCache\SimpleCacheAdapter;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Command to fetch a browscap ini file from the remote host and store the content in a local file
19
 */
20
class FetchCommand extends Command
21
{
22
    /**
23
     * @var string
24
     */
25
    private $defaultIniFile;
26
27
    /**
28
     * @var string
29
     */
30
    private $defaultCacheFolder;
31
32
    public function __construct(string $defaultCacheFolder, string $defaultIniFile)
33
    {
34
        $this->defaultCacheFolder = $defaultCacheFolder;
35
        $this->defaultIniFile = $defaultIniFile;
36
37
        parent::__construct();
38
    }
39
40 1 View Code Duplication
    protected function configure() : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
    {
42
        $this
43 1
            ->setName('browscap:fetch')
44 1
            ->setDescription('Fetches an updated INI file for Browscap.')
45 1
            ->addArgument(
46 1
                'file',
47 1
                InputArgument::OPTIONAL,
48 1
                'browscap.ini file',
49 1
                $this->defaultIniFile
50
            )
51 1
            ->addOption(
52 1
                'remote-file',
53 1
                'r',
54 1
                InputOption::VALUE_OPTIONAL,
55 1
                'browscap.ini file to download from remote location (possible values are: ' . IniLoaderInterface::PHP_INI_LITE
56 1
                . ', ' . IniLoaderInterface::PHP_INI . ', ' . IniLoaderInterface::PHP_INI_FULL . ')',
57 1
                IniLoaderInterface::PHP_INI
58
            )
59 1
            ->addOption(
60 1
                'cache',
61 1
                'c',
62 1
                InputOption::VALUE_OPTIONAL,
63 1
                'Where the cache files are located',
64 1
                $this->defaultCacheFolder
65
            );
66 1
    }
67
68 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output) : void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $logger = LoggerHelper::createDefaultLogger($output);
71
72
        $fileCache = new FilesystemCache($input->getOption('cache'));
73
        $cache = new SimpleCacheAdapter($fileCache);
74
75
        $file = $input->getArgument('file');
76
        if (! $file) {
77
            $file = $this->defaultIniFile;
78
        }
79
80
        $logger->info('started fetching remote file');
81
82
        $browscap = new BrowscapUpdater($cache, $logger);
83
        $browscap->fetch($file, $input->getOption('remote-file'));
84
85
        $logger->info('finished fetching remote file');
86
    }
87
}
88