Completed
Push — master ( c06f74...9254f0 )
by James
02:57
created

ApacheWebServer::parseActiveConfig()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 21
Code Lines 10

Duplication

Lines 9
Ratio 42.86 %

Code Coverage

Tests 8
CRAP Score 6.9683

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 21
ccs 8
cts 14
cp 0.5714
rs 8.7624
cc 5
eloc 10
nc 9
nop 1
crap 6.9683
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
/**
15
 * ApacheWebServer is the webserver class for apache httpd webserver.
16
 */
17
class ApacheWebServer extends WebServer
18
{
19
    /**
20
     * Constructor.
21
     *
22
     * @param string $version the semver-like version of the apache webserver
23
     */
24 15
    public function __construct($version = '')
25
    {
26 15
        parent::__construct('apache', $version);
27 15
    }
28
29 3
    public function extractVersion($settings = '')
30
    {
31 3
        return $this->match('/^Server version: Apache\/([0-9\.]+) .*/', $settings);
32
    }
33
34 3
    public function extractRootConfigurationFile($settings = '')
35
    {
36 3
        return $this->match('/ -D SERVER_CONFIG_FILE="([^"]+)"/', $settings);
37
    }
38
39 1
    public function parseActiveConfig(array $activeConfig = array())
40
    {
41 1
        $parsedActiveConfig = [];
42
43 1
        foreach ($activeConfig as $line => $directive) {
44 1 View Code Duplication
            if (preg_match('/^<If(Module|Define)\s+(\w+)>/i', trim($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...
45
                $parsedActiveConfig[$line] = ['module section', $matches[2]];
46
            }
47 1 View Code Duplication
            if (preg_match('/^<(((Directory|Files|Location)(Match)?)|VirtualHost)/i', trim($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...
48
                $parsedActiveConfig[$line] = ['scope section', $matches[2]];
49
            }
50
            /*if (preg_match('/^Include(Optional)?\s+(.+)/i', trim($directive), $matches)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
                $parsedActiveConfig[$line] = ['include directive', $matches[2]];
52
            }*/
53 1 View Code Duplication
            if (preg_match('/^(\w+)\s+(.+)/i', trim($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...
54
                $parsedActiveConfig[$line] = ['directive', [$matches[1], $matches[2]]];
55
            }
56 1
        }
57
58 1
        return $parsedActiveConfig;
59
    }
60
}
61