Completed
Push — master ( f24edd...b4a558 )
by wen
03:13
created

Config::getColumns()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 0
1
<?php
2
3
namespace Sco\Admin\Config;
4
5
use Illuminate\Config\Repository as ConfigRepository;
6
use Illuminate\Foundation\Application;
7
use Sco\Attributes\HasOriginalAndAttributesTrait;
8
9
abstract class Config
10
{
11
    use HasOriginalAndAttributesTrait;
12
13
    protected $app;
14
    protected $name;
15
    protected $config;
16
17
    protected $title;
18
    protected $permissions;
19
    protected $columns;
20
21 View Code Duplication
    public function __construct(Application $app, $name)
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...
22
    {
23
        $this->app  = $app;
24
        $this->name = $name;
25
26
        $this->config = new ConfigRepository(
27
            $this->app['files']->getRequire($this->getConfigFile())
28
        );
29
    }
30
31
    public function getConfigFile()
32
    {
33
        return $this->app['path.config']
34
            . DIRECTORY_SEPARATOR . 'admin'
35
            . DIRECTORY_SEPARATOR . $this->name . '.php';
36
    }
37
38
    public function getTitle()
39
    {
40
        if (!$this->title) {
41
            $this->title = $this->config->get('title');
42
        }
43
44
        return $this->title;
45
    }
46
47
    /**
48
     * @return \Sco\Admin\Config\PermissionsConfig
49
     */
50
    public function getPermissions()
51
    {
52
        if (!$this->permissions) {
53
            $config = $this->config->get('permissions');
54
55
            $this->permissions = new PermissionsConfig($config);
56
        }
57
58
        return $this->permissions;
59
    }
60
61 View Code Duplication
    public 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...
62
    {
63
        $columns = $this->getAttribute('columns', collect());
64
        if ($columns->isEmpty()) {
65
            $options = $this->getOriginal('columns');
66
            foreach ($options as $option) {
67
                $columns->push(app('admin.column')->make($option));
68
            }
69
70
            $this->setAttribute('columns', $columns);
71
        }
72
73
        return $columns;
74
    }
75
76 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...
77
    {
78
        $fields = $this->getAttribute('fields', collect());
79
        if ($fields->isEmpty()) {
80
            $options = $this->getOriginal('fields');
81
82
            foreach ($options as $option) {
83
                $fields->push($option);
84
            }
85
            $this->setAttribute('columns', $fields);
86
        }
87
88
        return $fields;
89
    }
90
91
    public function getConfigs()
92
    {
93
        $this->setAttribute([
94
            'title'       => $this->getTitle(),
95
            'permissions' => $this->getPermissions(),
96
            //'columns'     => $this->getColumns(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
97
        ]);
98
99
        return $this->getAttributes();
100
    }
101
102
103
    public function __toString()
104
    {
105
        return $this->toJson();
106
    }
107
}
108