Conditions | 6 |
Paths | 12 |
Total Lines | 53 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
96 | private static function processFolder(string $class, string $route, string $module, string $controller, string $method): bool |
||
97 | { |
||
98 | /** |
||
99 | * Defines the full path ($realpath) to the modules folder ($route). |
||
100 | */ |
||
101 | $realpath = realpath(constant('APP_PATH') . '/' . $route); |
||
102 | |||
103 | /** |
||
104 | * Adds the module to the path ($basepath), if it's a module. |
||
105 | */ |
||
106 | $basepath = $realpath; |
||
107 | if (!empty($module)) { |
||
108 | $basepath = $realpath . '/' . $module; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Defines full classname and filename |
||
113 | */ |
||
114 | $className = $class . '\\' . $module . '\\Controller\\' . $controller; |
||
115 | $filename = $basepath . '/Controller/' . $controller . '.php'; |
||
116 | |||
117 | Debug::message('Filename: ' . $filename); |
||
118 | Debug::message('Class: ' . $className); |
||
119 | if (!file_exists($filename)) { |
||
120 | return false; |
||
121 | } |
||
122 | |||
123 | $controller = new $className(); |
||
124 | if ($controller === null) { |
||
125 | return false; |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * If the class exists and is successfully instantiated, the module blade templates folder |
||
130 | * is added, if they exist. |
||
131 | */ |
||
132 | if (method_exists($controller, 'setTemplatesPath')) { |
||
133 | $templates_path = $basepath . '/Templates'; |
||
134 | Debug::message('Templates: ' . $templates_path); |
||
135 | $controller->setTemplatesPath($templates_path); |
||
136 | } |
||
137 | |||
138 | if (!method_exists($controller, $method)) { |
||
139 | Debug::message('Method ' . $method . ' not found in controller ' . $className); |
||
140 | $method = 'index'; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Runs the index method to launch the controller. |
||
145 | */ |
||
146 | $controller->{$method}(); |
||
147 | |||
148 | return true; |
||
149 | } |
||
151 |