Completed
Pull Request — master (#155)
by Thomas
12:04
created

FetchCommand::getBrowscap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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\Helper\IniLoader;
35
use BrowscapPHP\Helper\LoggerHelper;
36
use Symfony\Component\Console\Command\Command;
37
use Symfony\Component\Console\Input\InputArgument;
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 and store the content in a local file
44
 *
45
 * @category   Browscap-PHP
46
 * @package    Command
47
 * @author     Dave Olsen, http://dmolsen.com
48
 * @author     Thomas Müller <[email protected]>
49
 * @copyright  Copyright (c) 1998-2015 Browser Capabilities Project
50
 * @version    3.0
51
 * @license    http://www.opensource.org/licenses/MIT MIT License
52
 * @link       https://github.com/browscap/browscap-php/
53
 */
54
class FetchCommand extends Command
55
{
56
    /**
57
     * @var string
58
     */
59
    private $defaultIniFile;
60
61
    /**
62
     * @param string $defaultIniFile
63
     */
64 1
    public function __construct($defaultIniFile)
65
    {
66 1
        $this->defaultIniFile = $defaultIniFile;
67
68 1
        parent::__construct();
69 1
    }
70
71
    /**
72
     * Configures the current command.
73
     */
74 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...
75
    {
76 1
        $this
77 1
            ->setName('browscap:fetch')
78 1
            ->setDescription('Fetches an updated INI file for Browscap.')
79 1
            ->addArgument(
80 1
                'file',
81 1
                InputArgument::OPTIONAL,
82 1
                'browscap.ini file',
83 1
                $this->defaultIniFile
84 1
            )
85 1
            ->addOption(
86 1
                'remote-file',
87 1
                'r',
88 1
                InputOption::VALUE_OPTIONAL,
89
                'browscap.ini file to download from remote location (possible values are: ' . IniLoader::PHP_INI_LITE
90 1
                . ', ' . IniLoader::PHP_INI . ', ' . IniLoader::PHP_INI_FULL . ')',
91
                IniLoader::PHP_INI
92 1
            )
93 1
            ->addOption(
94 1
                'debug',
95 1
                'd',
96 1
                InputOption::VALUE_NONE,
97
                'Should the debug mode entered?'
98 1
            )
99
        ;
100 1
    }
101
102
    /**
103
     * @param InputInterface  $input
104
     * @param OutputInterface $output
105
     *
106
     * @return int|null|void
107
     */
108
    protected function execute(InputInterface $input, OutputInterface $output)
109
    {
110
        $loggerHelper = new LoggerHelper();
111
        $logger       = $loggerHelper->create($input->getOption('debug'));
112
113
        $file = $input->getArgument('file');
114
        if (!$file) {
115
            $file = $this->defaultIniFile;
116
        }
117
118
        $logger->info('started fetching remote file');
119
120
        $browscap = new BrowscapUpdater();
121
122
        $browscap
123
            ->setLogger($logger)
124
            ->fetch($file, $input->getOption('remote-file'))
125
        ;
126
127
        $logger->info('finished fetching remote file');
128
    }
129
}
130