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

NginxWebServer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 14.63 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 57.14%

Importance

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