Total Complexity | 52 |
Total Lines | 166 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like Module often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Module, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Module |
||
17 | { |
||
18 | private $controller; |
||
19 | private $controller_class; |
||
20 | private $privilege; |
||
21 | private $module; |
||
22 | private $menu; |
||
23 | |||
24 | public function __construct() |
||
25 | { |
||
26 | $routeArray = request()->route()->getAction(); |
||
27 | $this->controller = class_basename($routeArray['controller']); |
||
28 | $this->controller = strtok($this->controller,"@"); |
||
29 | |||
30 | $className = "\\".$routeArray["namespace"]."\\".$this->controller; |
||
31 | if(class_exists($className)) { |
||
32 | $this->controller_class = new $className(); |
||
33 | $this->module = cb()->find("cb_modules",["controller"=>$this->controller]); |
||
34 | $this->menu = cb()->find("cb_menus",["cb_modules_id"=>$this->module->id]); |
||
35 | $this->menu = (!$this->menu)?cb()->find("cb_menus",["type"=>"path","path"=>request()->segment(2)]):$this->menu; |
||
36 | $this->privilege = DB::table("cb_role_privileges") |
||
37 | ->where("cb_menus_id", $this->menu->id) |
||
38 | ->where("cb_roles_id", cb()->session()->roleId()) |
||
39 | ->first(); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return \crocodicstudio\crudbooster\controllers\scaffolding\singletons\ColumnSingleton |
||
45 | */ |
||
46 | public function getColumnSingleton() |
||
49 | } |
||
50 | |||
51 | public function getData($key) { |
||
52 | return ($this->controller_class)?$this->controller_class->getData($key)?:cb()->getAppName():null; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return CBController |
||
57 | */ |
||
58 | public function getController() { |
||
59 | return ($this->controller_class)?$this->controller_class:null; |
||
60 | } |
||
61 | |||
62 | public function getPageTitle() |
||
63 | { |
||
64 | return ($this->controller_class)?$this->controller_class->getData("page_title")?:cb()->getAppName():null; |
||
65 | } |
||
66 | |||
67 | public function getTable() |
||
68 | { |
||
69 | return ($this->controller_class)?$this->controller_class->getData("table"):null; |
||
70 | } |
||
71 | |||
72 | public function getPageIcon() |
||
73 | { |
||
74 | return ($this->controller_class)?$this->controller_class->getData('page_icon')?:"fa fa-bars":null; |
||
75 | } |
||
76 | |||
77 | public function canBrowse() { |
||
78 | if($this->privilege) { |
||
79 | if($this->privilege->can_browse) return true; |
||
80 | else return false; |
||
81 | }else{ |
||
82 | return true; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | public function canCreate() { |
||
87 | if($this->privilege) { |
||
88 | if($this->privilege->can_create) return true; |
||
89 | else return false; |
||
90 | }else{ |
||
91 | return true; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | public function canRead() { |
||
96 | if($this->privilege) { |
||
97 | if($this->privilege->can_read) return true; |
||
98 | else return false; |
||
99 | }else{ |
||
100 | return true; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | public function canUpdate() { |
||
105 | if($this->privilege) { |
||
106 | if($this->privilege->can_update) return true; |
||
107 | else return false; |
||
108 | }else{ |
||
109 | return true; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | public function canDelete() { |
||
114 | if($this->privilege) { |
||
115 | if($this->privilege->can_delete) return true; |
||
116 | else return false; |
||
117 | }else{ |
||
118 | return true; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | public function addURL() |
||
128 | } |
||
129 | } |
||
130 | |||
131 | public function addSaveURL() |
||
132 | { |
||
133 | if($this->controller_class && method_exists($this->controller_class, 'postAddSave')) { |
||
134 | return action($this->controller.'@postAddSave'); |
||
135 | }else{ |
||
136 | return null; |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public function editURL($id = null) |
||
146 | } |
||
147 | } |
||
148 | |||
149 | public function editSaveURL($id = null) |
||
150 | { |
||
151 | if(method_exists($this->controller_class, 'postEditSave')) { |
||
152 | return action($this->controller.'@postEditSave',['id'=>$id]); |
||
153 | }else{ |
||
154 | return null; |
||
155 | } |
||
156 | } |
||
157 | |||
158 | public function detailURL($id=null) |
||
159 | { |
||
160 | if($this->controller_class && method_exists($this->controller_class, 'getDetail')) { |
||
161 | return action($this->controller.'@getDetail',['id'=>$id]); |
||
162 | }else{ |
||
163 | return null; |
||
164 | } |
||
165 | } |
||
166 | |||
167 | public function deleteURL($id=null) |
||
173 | } |
||
174 | } |
||
175 | |||
176 | public function url($path = null) |
||
182 | } |
||
183 | } |
||
184 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths