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

ParserCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 39.58 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 55.56%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 7
dl 19
loc 48
ccs 15
cts 27
cp 0.5556
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 19 19 1
A __construct() 0 6 1
A execute() 0 13 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\Browscap;
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\InputArgument;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Input\InputOption;
22
use Symfony\Component\Console\Output\OutputInterface;
23
24
/**
25
 * commands to parse a given useragent
26
 */
27
class ParserCommand 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 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...
42
    {
43
        $this
44 1
            ->setName('browscap:parse')
45 1
            ->setDescription('Parses a user agent string and dumps the results.')
46 1
            ->addArgument(
47 1
                'user-agent',
48 1
                InputArgument::REQUIRED,
49 1
                'User agent string to analyze',
50 1
                null
51
            )
52 1
            ->addOption(
53 1
                'cache',
54 1
                'c',
55 1
                InputOption::VALUE_OPTIONAL,
56 1
                'Where the cache files are located',
57 1
                $this->defaultCacheFolder
58
            );
59 1
    }
60
61
    protected function execute(InputInterface $input, OutputInterface $output) : void
62
    {
63
        $logger = LoggerHelper::createDefaultLogger($output);
64
65
        $fileCache = new FilesystemCache($input->getOption('cache'));
66
        $cache = new SimpleCacheAdapter($fileCache);
67
68
        $browscap = new Browscap($cache, $logger);
69
70
        $result = $browscap->getBrowser($input->getArgument('user-agent'));
71
72
        $output->writeln(json_encode($result, JSON_PRETTY_PRINT));
73
    }
74
}
75