Completed
Pull Request — master (#127)
by Thomas
10:50
created

CheckUpdateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 53.52 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 62.5%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 1
cbo 5
dl 38
loc 71
ccs 20
cts 32
cp 0.625
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 21 21 1
A execute() 17 17 1
A getBrowscap() 0 4 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
 * Copyright (c) 1998-2015 Browser Capabilities Project
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * copy of this software and associated documentation files (the "Software"),
7
 * to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * and/or sell copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included
13
 * in all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 *
23
 * @category   Browscap-PHP
24
 * @package    Command
25
 * @copyright  1998-2015 Browser Capabilities Project
26
 * @license    http://www.opensource.org/licenses/MIT MIT License
27
 * @link       https://github.com/browscap/browscap-php/
28
 * @since      added with version 3.0
29
 */
30
31
namespace BrowscapPHP\Command;
32
33
use BrowscapPHP\Browscap;
34
use BrowscapPHP\Cache\BrowscapCacheInterface;
35
use BrowscapPHP\Helper\IniLoader;
36
use BrowscapPHP\Helper\LoggerHelper;
37
use Symfony\Component\Console\Command\Command;
38
use Symfony\Component\Console\Input\InputInterface;
39
use Symfony\Component\Console\Input\InputOption;
40
use Symfony\Component\Console\Output\OutputInterface;
41
42
/**
43
 * command to fetch a browscap ini file from the remote host, convert it into an array and store the content in a local
44
 * file
45
 *
46
 * @category   Browscap-PHP
47
 * @package    Command
48
 * @author     Dave Olsen, http://dmolsen.com
49
 * @author     Thomas Müller <[email protected]>
50
 * @copyright  Copyright (c) 1998-2015 Browser Capabilities Project
51
 * @version    3.0
52
 * @license    http://www.opensource.org/licenses/MIT MIT License
53
 * @link       https://github.com/browscap/browscap-php/
54
 */
55
class CheckUpdateCommand extends Command
56
{
57
    /**
58
     * @var \BrowscapPHP\Cache\BrowscapCacheInterface
59
     */
60
    private $cache = null;
61
62
    /**
63
     * @param \BrowscapPHP\Cache\BrowscapCacheInterface $cache
64
     */
65 1
    public function __construct(BrowscapCacheInterface $cache)
66
    {
67 1
        parent::__construct();
68
69 1
        $this->cache = $cache;
70 1
    }
71
72
    /**
73
     * Configures the current command.
74
     */
75 1 View Code Duplication
    protected function configure()
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...
76
    {
77 1
        $this
78 1
            ->setName('browscap:check-update')
79 1
            ->setDescription('Checks if an updated INI file is available.')
80 1
            ->addOption(
81 1
                'debug',
82 1
                'd',
83 1
                InputOption::VALUE_NONE,
84
                'Should the debug mode entered?'
85 1
            )
86 1
            ->addOption(
87 1
                'remote-file',
88 1
                'r',
89 1
                InputOption::VALUE_OPTIONAL,
90
                'browscap.ini file to download from remote location (possible values are: ' . IniLoader::PHP_INI_LITE
91 1
                . ', ' . IniLoader::PHP_INI . ', ' . IniLoader::PHP_INI_FULL . ')',
92
                IniLoader::PHP_INI
93 1
            )
94
        ;
95 1
    }
96
97
    /**
98
     * @param InputInterface  $input
99
     * @param OutputInterface $output
100
     *
101
     * @return int|null|void
102
     */
103 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
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...
104
    {
105
        $loggerHelper = new LoggerHelper();
106
        $logger       = $loggerHelper->create($input->getOption('debug'));
107
108
        $logger->debug('started checking for new version of remote file');
109
110
        $browscap = $this->getBrowscap();
111
112
        $browscap
113
            ->setLogger($logger)
114
            ->setCache($this->cache)
115
            ->checkUpdate($input->getOption('remote-file'))
116
        ;
117
118
        $logger->debug('finished checking for new version of remote file');
119
    }
120
121
    private function getBrowscap()
122
    {
123
        return new Browscap();
124
    }
125
}
126