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

ConvertCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 65.08 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 45.45%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 7
dl 41
loc 63
ccs 15
cts 33
cp 0.4545
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 19 19 1
A execute() 22 22 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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