Completed
Push — master ( ac625a...8e4a6a )
by wen
03:23
created

Config::compileConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Config;
4
5
use Illuminate\Foundation\Application;
6
use Sco\Attributes\HasOriginalAndAttributesTrait;
7
8
abstract class Config
9
{
10
    use HasOriginalAndAttributesTrait;
11
12
    protected $app;
13
    protected $name;
14
    protected $config;
15
16
    protected $defaultPermissions = [
17
        'view'   => true,
18
        'create' => true,
19
        'update' => true,
20
        'delete' => true,
21
    ];
22
23
    public function __construct(Application $app, $name)
24
    {
25
        $this->app = $app;
26
        $this->name = $name;
27
28
        $this->config = $this->compileConfig();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->config is correct as $this->compileConfig() (which targets Sco\Admin\Config\Config::compileConfig()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
29
        //$this->setOriginal($attributes);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
        $this->getOptions();
31
    }
32
33
    protected function compileConfig()
34
    {
35
    }
36
37
    protected function getTitle()
38
    {
39
        $title = $this->getAttribute('title');
40
        if ($title) {
41
            return $title;
42
        }
43
44
        $title = $this->getOriginal('title');
45
        $this->setAttribute('title', $title);
46
        return $title;
47
    }
48
49
    protected function getPermissions()
50
    {
51
        $permissions = $this->getAttribute('permissions', collect());
52
        if ($permissions->isEmpty()) {
53
            $option = $this->getOriginal('permissions');
54
            if (is_array($option)) {
55
                $option = array_merge($this->defaultPermissions, $option);
56
                foreach ($option as $key => $item) {
57
                    $val = $item instanceof \Closure ? $item() : $item;
58
                    $permissions->put($key, $val ? true : false);
59
                }
60
            } else {
61
                $val = $option instanceof \Closure ? $option() : $option;
62
                foreach ($this->defaultPermissions as $key => $item) {
63
                    $permissions->put($key, $val ? true : false);
64
                }
65
            }
66
            $this->setAttribute('permissions', $permissions);
67
        }
68
69
        return $permissions;
70
    }
71
72 View Code Duplication
    protected function getColumns()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
73
    {
74
        $columns = $this->getAttribute('columns', collect());
75
        if ($columns->isEmpty()) {
76
            $options = $this->getOriginal('columns');
77
            foreach ($options as $option) {
78
                $columns->push(app('admin.column')->make($option));
79
            }
80
81
            $this->setAttribute('columns', $columns);
82
        }
83
84
        return $columns;
85
    }
86
87 View Code Duplication
    protected function getFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
88
    {
89
        $fields = $this->getAttribute('fields', collect());
90
        if ($fields->isEmpty()) {
91
            $options = $this->getOriginal('fields');
92
93
            foreach ($options as $option) {
94
                $fields->push($option);
95
            }
96
            $this->setAttribute('columns', $fields);
97
        }
98
99
        return $fields;
100
    }
101
102
    public function getOptions()
103
    {
104
        $this->getTitle();
105
        $this->getPermissions();
106
        //$this->getColumns();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
107
108
        return $this->getAttributes();
109
    }
110
111
    public function __toString()
112
    {
113
        return $this->toJson();
114
    }
115
}
116