Passed
Push — master ( f6367b...2f9400 )
by Iman
03:26
created

ControllerConfigParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toArray() 0 21 5
A parse() 0 10 1
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ModuleGenerator;
4
5
class ControllerConfigParser
6
{
7
    public static function parse($code)
8
    {
9
        $configCode = ScaffoldingParser::extract_unit($code, cbStartMarker('CONFIGURATION'), cbEndMarker('CONFIGURATION'));
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 = self::toArray($code, $configCode);
15
16
        return $result;
17
    }
18
19
    /**
20
     * @param $code
21
     * @param $configCode
22
     * @return array
23
     */
24
    private static function toArray($code, $configCode)
0 ignored issues
show
Unused Code introduced by
The parameter $code is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

24
    private static function toArray(/** @scrutinizer ignore-unused */ $code, $configCode)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $result = [];
27
        foreach ($configCode as &$code) {
0 ignored issues
show
introduced by
$code is overwriting one of the parameters of this function.
Loading history...
28
            $key = substr($code, 0, strpos($code, ' = '));
29
            $key = str_replace('$this->', '', $key);
30
            $val = substr($code, strpos($code, ' = ') + 3);
31
            $val = trim(str_replace("'", '"', $val), '"');
32
            if (strtolower($val) == "true") {
33
                $val = true;
34
            } elseif (strtolower($val) == "false") {
35
                $val = false;
36
            }
37
            if ($key == "") {
38
                continue;
39
            }
40
41
            $result[$key] = $val;
42
        }
43
44
        return $result;
45
    }
46
}