| Conditions | 11 |
| Paths | 49 |
| Total Lines | 51 |
| Code Lines | 38 |
| 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 |
||
| 51 | public static function run() |
||
| 52 | { |
||
| 53 | global $argv; |
||
|
|
|||
| 54 | $output = null; |
||
| 55 | if (!Obj::isArray($argv) || Str::likeEmpty($argv[1])) { |
||
| 56 | $output = 'Console command is unknown! Type "console main/help" to get help guide'; |
||
| 57 | } else { |
||
| 58 | $controller_action = $argv[1]; |
||
| 59 | $arrInput = explode('/', $controller_action); |
||
| 60 | $controller = ucfirst(strtolower($arrInput[0])); |
||
| 61 | $action = ucfirst(strtolower($arrInput[1])); |
||
| 62 | if($action == null) { |
||
| 63 | $action = 'Index'; |
||
| 64 | } |
||
| 65 | // set action and id |
||
| 66 | $action = 'action' . $action; |
||
| 67 | $id = null; |
||
| 68 | if (isset($argv[2])) { |
||
| 69 | $id = $argv[2]; |
||
| 70 | } |
||
| 71 | |||
| 72 | try { |
||
| 73 | $controller_path = '/Apps/Controller/' . env_name . '/' . $controller . '.php'; |
||
| 74 | if(file_exists(root . $controller_path) && is_readable(root . $controller_path)) { |
||
| 75 | include_once(root . $controller_path); |
||
| 76 | $cname = 'Apps\\Controller\\' . env_name . '\\' . $controller; |
||
| 77 | if(class_exists($cname)) { |
||
| 78 | $load = new $cname; |
||
| 79 | if(method_exists($cname, $action)) { |
||
| 80 | if($id !== null) { |
||
| 81 | $output = @$load->$action($id); |
||
| 82 | } else { |
||
| 83 | $output = @$load->$action(); |
||
| 84 | } |
||
| 85 | } else { |
||
| 86 | throw new NativeException('Method ' . $action . '() not founded in ' . $cname . ' in file {root}' . $controller_path); |
||
| 87 | } |
||
| 88 | unset($load); |
||
| 89 | } else { |
||
| 90 | throw new NativeException('Namespace\\Class - ' . $cname . ' not founded in {root}' . $controller_path); |
||
| 91 | } |
||
| 92 | } else { |
||
| 93 | throw new NativeException('Controller not founded: {root}' . $controller_path); |
||
| 94 | } |
||
| 95 | } catch(NativeException $e) { |
||
| 96 | $e->display($e->getMessage()); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | return App::$Output->write($output); |
||
| 101 | } |
||
| 102 | |||
| 103 | } |
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state