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

FetchCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 67.65 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 56.41%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 7
dl 46
loc 68
ccs 22
cts 39
cp 0.5641
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B configure() 27 27 1
A execute() 19 19 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\IniLoaderInterface;
16
use BrowscapPHP\Helper\LoggerHelper;
17
use Doctrine\Common\Cache\FilesystemCache;
18
use Roave\DoctrineSimpleCache\SimpleCacheAdapter;
19
use Symfony\Component\Console\Command\Command;
20
use Symfony\Component\Console\Input\InputArgument;
21
use Symfony\Component\Console\Input\InputInterface;
22
use Symfony\Component\Console\Input\InputOption;
23
use Symfony\Component\Console\Output\OutputInterface;
24
25
/**
26
 * Command to fetch a browscap ini file from the remote host and store the content in a local file
27
 */
28
class FetchCommand extends Command
29
{
30
    /**
31
     * @var string
32
     */
33
    private $defaultIniFile;
34
35
    /**
36
     * @var string
37
     */
38
    private $defaultCacheFolder;
39
40
    public function __construct(string $defaultCacheFolder, string $defaultIniFile)
41
    {
42
        $this->defaultCacheFolder = $defaultCacheFolder;
43
        $this->defaultIniFile = $defaultIniFile;
44
45
        parent::__construct();
46
    }
47
48 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...
49
    {
50
        $this
51 1
            ->setName('browscap:fetch')
52 1
            ->setDescription('Fetches an updated INI file for Browscap.')
53 1
            ->addArgument(
54 1
                'file',
55 1
                InputArgument::OPTIONAL,
56 1
                'browscap.ini file',
57 1
                $this->defaultIniFile
58
            )
59 1
            ->addOption(
60 1
                'remote-file',
61 1
                'r',
62 1
                InputOption::VALUE_OPTIONAL,
63 1
                'browscap.ini file to download from remote location (possible values are: ' . IniLoaderInterface::PHP_INI_LITE
64 1
                . ', ' . IniLoaderInterface::PHP_INI . ', ' . IniLoaderInterface::PHP_INI_FULL . ')',
65 1
                IniLoaderInterface::PHP_INI
66
            )
67 1
            ->addOption(
68 1
                'cache',
69 1
                'c',
70 1
                InputOption::VALUE_OPTIONAL,
71 1
                'Where the cache files are located',
72 1
                $this->defaultCacheFolder
73
            );
74 1
    }
75
76 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...
77
    {
78
        $logger = LoggerHelper::createDefaultLogger($output);
79
80
        $fileCache = new FilesystemCache($input->getOption('cache'));
81
        $cache = new SimpleCacheAdapter($fileCache);
82
83
        $file = $input->getArgument('file');
84
        if (! $file) {
85
            $file = $this->defaultIniFile;
86
        }
87
88
        $logger->info('started fetching remote file');
89
90
        $browscap = new BrowscapUpdater($cache, $logger);
91
        $browscap->fetch($file, $input->getOption('remote-file'));
92
93
        $logger->info('finished fetching remote file');
94
    }
95
}
96