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

BaseCommand::getWebServer()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 4
Ratio 17.39 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 23
rs 9.0856
cc 3
eloc 15
nc 4
nop 2
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