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

ApacheWebServer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 20.45 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 8
c 7
b 1
f 1
lcom 0
cbo 1
dl 9
loc 44
ccs 15
cts 21
cp 0.7143
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extractVersion() 0 4 1
A extractRootConfigurationFile() 0 4 1
B parseActiveConfig() 9 21 5

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\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