Completed
Push — master ( 47252c...69fb56 )
by James
03:42
created

ApacheWebServer::parseActiveConfig()   C

Complexity

Conditions 7
Paths 33

Size

Total Lines 24
Code Lines 14

Duplication

Lines 3
Ratio 12.5 %

Code Coverage

Tests 5
CRAP Score 27.6718

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 3
loc 24
ccs 5
cts 20
cp 0.25
rs 6.7272
cc 7
eloc 14
nc 33
nop 1
crap 27.6718
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\WebServer;
13
14
use JamesRezo\WebHelper\WebServer\ApacheWebServer\Directive;
15
16
/**
17
 * ApacheWebServer is the webserver class for apache httpd webserver.
18
 */
19
class ApacheWebServer extends WebServer
20
{
21
    /**
22
     * Constructor.
23
     *
24
     * @param string $version the semver-like version of the apache webserver
25
     */
26 15
    public function __construct($version = '')
27
    {
28 15
        parent::__construct('apache', $version);
29 15
    }
30
31 3
    public function extractVersion($settings = '')
32
    {
33 3
        return $this->match('/^Server version: Apache\/([0-9\.]+) .*/', $settings);
34
    }
35
36 3
    public function extractRootConfigurationFile($settings = '')
37
    {
38 3
        return $this->match('/ -D SERVER_CONFIG_FILE="([^"]+)"/', $settings);
39
    }
40
41 1
    public function parseActiveConfig(array $activeConfig = array())
42
    {
43 1
        $parsedActiveConfig = [];
44
45 1
        foreach ($activeConfig as $line => $directive) {
46
            if (preg_match('/^<If(Module|Define)\s+(\w+)>/i', $directive, $matches)) {
47
                $parsedActiveConfig[$line] = ['module section', $matches[2]];
48
            }
49
            if (preg_match('/^<\/If(Module|Define)>/i', $directive, $matches)) {
50
                $parsedActiveConfig[$line] = ['end module section'];
51
            }
52 View Code Duplication
            if (preg_match('/^<(((Directory|Files|Location)(Match)?)|VirtualHost)/i', $directive, $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...
53
                $parsedActiveConfig[$line] = ['scope section', $matches[2]];
54
            }
55
            if (preg_match('/^<\/(((Directory|Files|Location)(Match)?)|VirtualHost)/i', $directive, $matches)) {
56
                $parsedActiveConfig[$line] = ['end scope section'];
57
            }
58
            if (preg_match('/^(\w+)\s+(.+)/i', $directive, $matches)) {
59
                $parsedActiveConfig[$line] = new Directive($matches[1], $matches[2]);
60
            }
61 1
        }
62
63 1
        return $parsedActiveConfig;
64
    }
65
}
66