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

NginxWebServer::parseActiveConfig()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 18
Code Lines 10

Duplication

Lines 9
Ratio 50 %

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 18
ccs 8
cts 14
cp 0.5714
rs 8.8571
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
 * 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