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

ConvertCommand::getCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 3
cts 5
cp 0.6
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2.2559
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Command;
5
6
use BrowscapPHP\BrowscapUpdater;
7
use BrowscapPHP\Helper\LoggerHelper;
8
use Doctrine\Common\Cache\FilesystemCache;
9
use Roave\DoctrineSimpleCache\SimpleCacheAdapter;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputArgument;
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 convert a downloaded Browscap ini file and write it to the cache
18
 */
19
class ConvertCommand extends Command
20
{
21
    /**
22
     * @var string
23
     */
24
    private $defaultIniFile;
25
26
    /**
27
     * @var string
28
     */
29
    private $defaultCacheFolder;
30
31
    public function __construct(string $defaultCacheFolder, string $defaultIniFile)
32
    {
33
        $this->defaultCacheFolder = $defaultCacheFolder;
34
        $this->defaultIniFile = $defaultIniFile;
35
36
        parent::__construct();
37
    }
38
39 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...
40
    {
41
        $this
42 1
            ->setName('browscap:convert')
43 1
            ->setDescription('Converts an existing browscap.ini file to a cache.php file.')
44 1
            ->addArgument(
45 1
                'file',
46 1
                InputArgument::OPTIONAL,
47 1
                'Path to the browscap.ini file',
48 1
                $this->defaultIniFile
49
            )
50 1
            ->addOption(
51 1
                'cache',
52 1
                'c',
53 1
                InputOption::VALUE_OPTIONAL,
54 1
                'Where the cache files are located',
55 1
                $this->defaultCacheFolder
56
            );
57 1
    }
58
59 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...
60
    {
61
        $logger = LoggerHelper::createDefaultLogger($output);
62
63
        $fileCache = new FilesystemCache($input->getOption('cache'));
64
        $cache = new SimpleCacheAdapter($fileCache);
65
66
        $logger->info('initializing converting process');
67
68
        $browscap = new BrowscapUpdater($cache, $logger);
69
70
        $logger->info('started converting local file');
71
72
        $file = $input->getArgument('file');
73
        if (! $file) {
74
            $file = $this->defaultIniFile;
75
        }
76
77
        $browscap->convertFile($file);
78
79
        $logger->info('finished converting local file');
80
    }
81
}
82