Completed
Pull Request — master (#157)
by Thomas
13:25
created

CheckUpdateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 3
Metric Value
c 4
b 0
f 3
dl 0
loc 20
ccs 17
cts 17
cp 1
rs 9.4285
cc 1
eloc 15
nc 1
nop 0
crap 1
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\BrowscapUpdater;
34
use BrowscapPHP\Cache\BrowscapCache;
35
use BrowscapPHP\Cache\BrowscapCacheInterface;
36
use BrowscapPHP\Helper\IniLoader;
37
use BrowscapPHP\Helper\LoggerHelper;
38
use Symfony\Component\Console\Command\Command;
39
use Symfony\Component\Console\Input\InputInterface;
40
use Symfony\Component\Console\Input\InputOption;
41
use Symfony\Component\Console\Output\OutputInterface;
42
use WurflCache\Adapter\File;
43
44
/**
45
 * command to fetch a browscap ini file from the remote host, convert it into an array and store the content in a local
46
 * file
47
 *
48
 * @category   Browscap-PHP
49
 * @package    Command
50
 * @author     Dave Olsen, http://dmolsen.com
51
 * @author     Thomas Müller <[email protected]>
52
 * @copyright  Copyright (c) 1998-2015 Browser Capabilities Project
53
 * @version    3.0
54
 * @license    http://www.opensource.org/licenses/MIT MIT License
55
 * @link       https://github.com/browscap/browscap-php/
56
 */
57
class CheckUpdateCommand extends Command
58
{
59
    /**
60
     * @var BrowscapCacheInterface
61
     */
62
    private $cache = null;
63
64
    /**
65
     * @var string
66
     */
67
    private $defaultCacheFolder;
68
69
    /**
70
     * @param string $defaultCacheFolder
71
     */
72 1
    public function __construct($defaultCacheFolder)
73
    {
74 1
        $this->defaultCacheFolder = $defaultCacheFolder;
75
76 1
        parent::__construct();
77 1
    }
78
79
    /**
80
     * @param \BrowscapPHP\Cache\BrowscapCacheInterface $cache
81
     *
82
     * @return $this
83
     */
84 1
    public function setCache(BrowscapCacheInterface $cache)
85
    {
86 1
        $this->cache = $cache;
87
88 1
        return $this;
89
    }
90
91
    /**
92
     * Configures the current command.
93
     */
94 1
    protected function configure()
95
    {
96 1
        $this
97 1
            ->setName('browscap:check-update')
98 1
            ->setDescription('Checks if an updated INI file is available.')
99 1
            ->addOption(
100 1
                'debug',
101 1
                'd',
102 1
                InputOption::VALUE_NONE,
103
                'Should the debug mode entered?'
104 1
            )
105 1
            ->addOption(
106 1
                'cache',
107 1
                'c',
108 1
                InputOption::VALUE_OPTIONAL,
109 1
                'Where the cache files are located',
110 1
                $this->defaultCacheFolder
111 1
            )
112
        ;
113 1
    }
114
115
    /**
116
     * @param InputInterface  $input
117
     * @param OutputInterface $output
118
     *
119
     * @return int|null|void
120
     */
121 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...
122
    {
123
        $loggerHelper = new LoggerHelper();
124
        $logger       = $loggerHelper->create($input->getOption('debug'));
125
126
        $logger->debug('started checking for new version of remote file');
127
128
        $browscap = new BrowscapUpdater();
129
130
        $browscap
131
            ->setLogger($logger)
132
            ->setCache($this->getCache($input))
133
            ->checkUpdate()
134
        ;
135
136
        $logger->debug('finished checking for new version of remote file');
137
    }
138
139
    /**
140
     * @param InputInterface $input
141
     *
142
     * @return BrowscapCacheInterface
143
     */
144 View Code Duplication
    private function getCache(InputInterface $input)
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...
145
    {
146
        if (null === $this->cache) {
147
            $cacheAdapter = new File(array(File::DIR => $input->getOption('cache')));
148
            $this->cache  = new BrowscapCache($cacheAdapter);
149
        }
150
151
        return $this->cache;
152
    }
153
}
154