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