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

FileManipulator::stringify()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 5
nop 2
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ModuleGenerator;
4
5
class FileManipulator
6
{
7
    static function putCtrlContent($ctrl, $fileContent)
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
        return file_put_contents(controller_path($ctrl), $fileContent);
10
    }
11
12
    static function readCtrlContent($ctrl)
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...
13
    {
14
        return file_get_contents(controller_path($ctrl));
15
    }
16
17
    public static function extractBetween($raw, $mark)
18
    {
19
        list($before, $_rest) = explode("# START $mark DO NOT REMOVE THIS LINE", $raw);
20
        list($_middle, $after) = explode("# END $mark DO NOT REMOVE THIS LINE", $_rest);
21
22
        return [trim($before), trim($_middle), trim($after)];
23
    }
24
25
    /**
26
     * @param $phpCode
27
     * @param $mark
28
     * @param $newCode
29
     * @return string
30
     */
31
    public static function replaceBetweenMark($phpCode, $mark, $newCode)
32
    {
33
        list($top, $_middle, $bottom) = self::extractBetween($phpCode, $mark);
34
35
        $_code = $top."\n\n";
36
        $_code .= str_repeat(' ', 12)."# START $mark DO NOT REMOVE THIS LINE\n";
37
        $_code .= $newCode."\n";
38
        $_code .= str_repeat(' ', 12)."# END $mark DO NOT REMOVE THIS LINE\n\n";
39
        $_code .= str_repeat(' ', 12).$bottom;
40
41
        return $_code;
42
    }
43
44
    public static function stringify($input, $indent = "")
45
    {
46
        if (! is_array($input)) {
47
            return var_export($input, true);
48
        }
49
        $buffer = [];
50
        foreach ($input as $key => $value) {
51
            $buffer[] = $indent.var_export($key, true)."=>".min_var_export($value, ($indent."    "));
0 ignored issues
show
Bug introduced by
The function min_var_export was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

51
            $buffer[] = $indent.var_export($key, true)."=>"./** @scrutinizer ignore-call */ min_var_export($value, ($indent."    "));
Loading history...
52
        }
53
        if (empty($buffer)) {
54
            return "[]";
55
        }
56
57
        return "[\n".implode(",\n", $buffer)."\n$indent]";
58
    }
59
}