Completed
Pull Request — master (#221)
by Thomas
28:24 queued 26:59
created

ConvertCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 12

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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