Passed
Push — master ( 56f21d...a5762d )
by Iman
03:49
created

PhpColConfig::makeColumnPhpCode()   C

Complexity

Conditions 7
Paths 18

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 18
nop 0
dl 0
loc 36
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ModuleGenerator;
4
5
class PhpColConfig
6
{
7
    /**
8
     * @return array
9
     */
10
    public static function makeColumnPhpCode()
11
    {
12
        $labels = request('column');
13
        $name = request('name');
14
        $isImage = request('is_image');
15
        $isDownload = request('is_download');
16
        $callback = request('callback');
17
        $width = request('width');
18
19
        $indent = str_repeat(' ', 8);
20
21
        $columnScript = [];
22
        $columnScript[] = $indent.'$this->col[] = [];';
23
        foreach ($labels as $i => $label) {
24
25
            if (! $name[$i]) {
26
                continue;
27
            }
28
29
            $colProperties = ["'label' => '$label'", "'name' => '{$name[$i]}'"];
30
            if ($isImage[$i]) {
31
                $colProperties[] = '"image" => true ';
32
            }
33
            if ($isDownload[$i]) {
34
                $colProperties[] = '"download" => true';
35
            }
36
            if ($callback[$i]) {
37
                $colProperties[] = '"callback" => function($row) {'.$callback[$i].'}';
38
            }
39
            if ($width[$i]) {
40
                $colProperties[] = "'width' => '$width[$i]'";
41
            }
42
43
            $columnScript[] = $indent.'$this->col[] = ['.implode(", ", $colProperties).'];';
44
        }
45
        return implode("\n", $columnScript);
0 ignored issues
show
Bug Best Practice introduced by
The expression return implode(' ', $columnScript) returns the type string which is incompatible with the documented return type array.
Loading history...
46
    }
47
48
}