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

UpdateCommand::getCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
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\InputInterface;
13
use Symfony\Component\Console\Input\InputOption;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Command to fetch a browscap ini file from the remote host, convert it into an array and store the content in a local
18
 * file
19
 */
20
class UpdateCommand extends Command
21
{
22
    /**
23
     * @var string
24
     */
25
    private $defaultCacheFolder;
26
27
    public function __construct(string $defaultCacheFolder)
28
    {
29
        $this->defaultCacheFolder = $defaultCacheFolder;
30
31
        parent::__construct();
32
    }
33
34 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...
35
    {
36
        $this
37 1
            ->setName('browscap:update')
38 1
            ->setDescription('Fetches an updated INI file for Browscap and overwrites the current PHP file.')
39 1
            ->addOption(
40 1
                'remote-file',
41 1
                'r',
42 1
                InputOption::VALUE_OPTIONAL,
43 1
                'browscap.ini file to download from remote location (possible values are: ' . IniLoaderInterface::PHP_INI_LITE
44 1
                . ', ' . IniLoaderInterface::PHP_INI . ', ' . IniLoaderInterface::PHP_INI_FULL . ')',
45 1
                IniLoaderInterface::PHP_INI
46
            )
47 1
            ->addOption(
48 1
                'no-backup',
49 1
                null,
50 1
                InputOption::VALUE_NONE,
51 1
                'Do not backup the previously existing file'
52
            )
53 1
            ->addOption(
54 1
                'cache',
55 1
                'c',
56 1
                InputOption::VALUE_OPTIONAL,
57 1
                'Where the cache files are located',
58 1
                $this->defaultCacheFolder
59
            );
60 1
    }
61
62 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...
63
    {
64
        $logger = LoggerHelper::createDefaultLogger($output);
65
66
        $fileCache = new FilesystemCache($input->getOption('cache'));
67
        $cache = new SimpleCacheAdapter($fileCache);
68
69
        $logger->info('started updating cache with remote file');
70
71
        $browscap = new BrowscapUpdater($cache, $logger);
72
        $browscap->update($input->getOption('remote-file'));
73
74
        $logger->info('finished updating cache with remote file');
75
    }
76
}
77