Conditions | 6 |
Paths | 32 |
Total Lines | 52 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
40 | public static function run(string $module, string $controller, string $method): bool |
||
41 | { |
||
42 | Debug::initialize(); |
||
43 | |||
44 | $routes = Routes::getAllRoutes(); |
||
45 | $endpoint = $routes['Controller'][$module][$controller] ?? null; |
||
46 | if ($endpoint === null) { |
||
47 | static::dieWithMessage($module . '::' . $controller . 'does not exists'); |
||
48 | } |
||
49 | |||
50 | Debug::message("Dispatcher::runWeb executing $module::$controller ($endpoint)"); |
||
51 | $route_array = explode('|', $endpoint); |
||
52 | $className = $route_array[0]; |
||
53 | $filename = $route_array[1]; |
||
54 | |||
55 | if (!file_exists($filename)) { |
||
56 | static::dieWithMessage($filename . 'does not exists'); |
||
57 | } |
||
58 | |||
59 | require_once $filename; |
||
60 | |||
61 | $controllerClass = new $className(); |
||
62 | if ($controllerClass === null) { |
||
63 | static::dieWithMessage($className . ' not found'); |
||
64 | } |
||
65 | |||
66 | $templates_path = [ |
||
67 | constant('ALX_PATH') . '/src/Modules/' . $module . '/Templates/', |
||
68 | constant('BASE_PATH') . '/../Modules/' . $module . '/Templates/', |
||
69 | ]; |
||
70 | |||
71 | /** |
||
72 | * If the class exists and is successfully instantiated, the module blade templates folder |
||
73 | * is added, if they exist. |
||
74 | */ |
||
75 | if (method_exists($controllerClass, 'setTemplatesPath')) { |
||
76 | Debug::message('Templates: ' . $templates_path[0]); |
||
77 | Debug::message('Templates: ' . $templates_path[1]); |
||
78 | $controllerClass->setTemplatesPath($templates_path); |
||
79 | } |
||
80 | |||
81 | if (!method_exists($controllerClass, $method)) { |
||
82 | Debug::message('Method ' . $method . ' not found in controller ' . $className); |
||
83 | $method = 'index'; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Runs the index method to launch the controller. |
||
88 | */ |
||
89 | $controllerClass->{$method}(); |
||
90 | |||
91 | return true; |
||
92 | } |
||
100 |