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

NginxWebServer::parseActiveConfig()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 18
Code Lines 10

Duplication

Lines 6
Ratio 33.33 %

Code Coverage

Tests 5
CRAP Score 11.643

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 6
loc 18
ccs 5
cts 14
cp 0.357
rs 8.8571
cc 5
eloc 10
nc 9
nop 1
crap 11.643
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