BaseCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 37
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 10 2
A getWebServer() 0 23 3
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 4
    protected function getPath(InputInterface $input)
26
    {
27 4
        $path = $input->getArgument('path');
28
29 4
        if (empty($path)) {
30 1
            $path = explode(PATH_SEPARATOR, getenv('PATH'));
31 1
        }
32
33 4
        return $path;
34
    }
35
36 7
    protected function getWebServer(InputInterface $input, OutputInterface $output)
37
    {
38 7
        $webservername = $input->getArgument('webserver');
39 7
        $version = 0;
40 7
        if (preg_match(',([^:]+)(:([\.\d]+))$,', $webservername, $matches)) {
41 3
            $version = $matches[3];
42 3
            $webservername = $matches[1];
43 3
        }
44
45 7
        $factory = new Factory();
46
47 7
        $webserver = $factory->createWebServer($webservername, $version);
48 7
        if ($webserver instanceof NullWebServer) {
49 2
            $output->writeln('<error>Web Server "'.$webservername.'" unknown.</error>');
50 2
            $output->writeln(
51
                '<comment>Known Web Servers are '.
52 2
                implode(' or ', $factory->getKnownWebServers()).
53
                '.</comment>'
54 2
            );
55 2
        }
56
57 7
        return $webserver;
58
    }
59
}
60