Passed
Push — master ( 3388c8...01e728 )
by Iman
08:15 queued 02:52
created

ControllerConfigParser::parse()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 26
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 19
nc 7
nop 1
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ModuleGenerator;
4
5
class ControllerConfigParser
6
{
7
    static function parse($code)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
8
    {
9
        $configCode = extract_unit($code, "# START CONFIGURATION DO NOT REMOVE THIS LINE", "# END CONFIGURATION DO NOT REMOVE THIS LINE");
10
        $configCode = preg_replace('/[\t\n\r\0\x0B]/', '', $configCode);
11
        $configCode = preg_replace('/([\s])\1+/', ' ', $configCode);
12
        $configCode = explode(";", $configCode);
13
        $configCode = array_map('trim', $configCode);
14
        $result = [];
15
        foreach ($configCode as &$code) {
0 ignored issues
show
introduced by
$code is overwriting one of the parameters of this function.
Loading history...
16
            $key = substr($code, 0, strpos($code, ' = '));
17
            $key = str_replace('$this->', '', $key);
18
            $val = substr($code, strpos($code, ' = ') + 3);
19
            $val = trim(str_replace("'", '"', $val), '"');
20
            if (strtolower($val) == "true") {
21
                $val = true;
22
            } elseif (strtolower($val) == "false") {
23
                $val = false;
24
            }
25
            if ($key == "") {
26
                continue;
27
            }
28
29
            $result[$key] = $val;
30
        }
31
32
        return $result;
33
    }
34
}