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

CheckUpdateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 32.56 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 43.48%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 7
dl 14
loc 43
ccs 10
cts 23
cp 0.4348
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 13 1
A __construct() 0 6 1
A execute() 14 14 1

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\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * Command to fetch a browscap ini file from the remote host, convert it into an array and store the content in a local
25
 * file
26
 */
27
class CheckUpdateCommand extends Command
28
{
29
    /**
30
     * @var string
31
     */
32
    private $defaultCacheFolder;
33
34
    public function __construct(string $defaultCacheFolder)
35
    {
36
        $this->defaultCacheFolder = $defaultCacheFolder;
37
38
        parent::__construct();
39
    }
40
41 1
    protected function configure() : void
42
    {
43
        $this
44 1
            ->setName('browscap:check-update')
45 1
            ->setDescription('Checks if an updated INI file is available.')
46 1
            ->addOption(
47 1
                'cache',
48 1
                'c',
49 1
                InputOption::VALUE_OPTIONAL,
50 1
                'Where the cache files are located',
51 1
                $this->defaultCacheFolder
52
            );
53 1
    }
54
55 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...
56
    {
57
        $logger = LoggerHelper::createDefaultLogger($output);
58
59
        $fileCache = new FilesystemCache($input->getOption('cache'));
60
        $cache = new SimpleCacheAdapter($fileCache);
61
62
        $logger->debug('started checking for new version of remote file');
63
64
        $browscap = new BrowscapUpdater($cache, $logger);
65
        $browscap->checkUpdate();
66
67
        $logger->debug('finished checking for new version of remote file');
68
    }
69
}
70