Completed
Push — master ( 85f4f7...c06f74 )
by James
03:18
created

BaseCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 10.81 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 4
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 10 2
A getWebServer() 4 23 3

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
/**
4
 * This file is, guess what, part of WebHelper.
5
 *
6
 * (c) James <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace JamesRezo\WebHelper\Command;
13
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use JamesRezo\WebHelper\Factory;
18
use JamesRezo\WebHelper\WebServer\NullWebServer;
19
20
/**
21
 * Base WebHelper command.
22
 */
23
class BaseCommand extends Command
24
{
25
    protected function getPath(InputInterface $input)
26
    {
27
        $path = $input->getArgument('path');
28
29
        if (empty($path)) {
30
            $path = explode(PATH_SEPARATOR, getenv('PATH'));
31
        }
32
33
        return $path;
34
    }
35
36
    protected function getWebServer(InputInterface $input, OutputInterface $output)
37
    {
38
        $webservername = $input->getArgument('webserver');
39
        $version = 0;
40 View Code Duplication
        if (preg_match(',([^:]+)(:([\.\d]+))$,', $webservername, $matches)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
41
            $version = $matches[3];
42
            $webservername = $matches[1];
43
        }
44
45
        $factory = new Factory();
46
47
        $webserver = $factory->createWebServer($webservername, $version);
48
        if ($webserver instanceof NullWebServer) {
49
            $output->writeln('<error>Web Server "'.$webservername.'" unknown.</error>');
50
            $output->writeln(
51
                '<comment>Known Web Servers are '.
52
                implode(' or ', $factory->getKnownWebServers()).
53
                '.</comment>'
54
            );
55
        }
56
57
        return $webserver;
58
    }
59
}
60