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

NginxWebServer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 21.95 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 8
c 5
b 0
f 2
lcom 0
cbo 1
dl 9
loc 41
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 18 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
 * NginxWebServer is the webserver class for nginx httpd webserver.
16
 */
17
class NginxWebServer extends WebServer
18
{
19
    /**
20
     * Constructor.
21
     *
22
     * @param string $version the semver-like version of the apache webserver
23
     */
24 12
    public function __construct($version = '')
25
    {
26 12
        parent::__construct('nginx', $version);
27 12
    }
28
29 4
    public function extractVersion($settings = '')
30
    {
31 4
        return $this->match('/^nginx version: nginx\/([0-9\.]+).*/', $settings);
32
    }
33
34 3
    public function extractRootConfigurationFile($settings = '')
35
    {
36 3
        return $this->match('/--conf-path=([^\s]+) /', $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('/(?P<key>\w+)\s+(?P<value>[^;]+);/', $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] = ['simple directive', [$matches['key'] => $matches['value']]];
46
            }
47 1 View Code Duplication
            if (preg_match('/(?P<key>\w+)\s+(?P<value>[^\s{+])\s*{/', $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] = ['block directive', [$matches['key'] => $matches['value']]];
49
            }
50 1 View Code Duplication
            if (preg_match('/(?P<key>\w+)\s*{/', $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...
51
                $parsedActiveConfig[$line] = ['context', $matches['key']];
52
            }
53 1
        }
54
55 1
        return $parsedActiveConfig;
56
    }
57
}
58