| Conditions | 5 |
| Paths | 7 |
| Total Lines | 72 |
| Code Lines | 53 |
| 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 |
||
| 79 | public function invoke() |
||
| 80 | { |
||
| 81 | $this->router->map('GET', '/', [ |
||
| 82 | 'Egzaminer\Roll\HomePage', 'indexAction', ]); |
||
| 83 | |||
| 84 | $this->router->map('GET', '/group/[i:id]', [ |
||
| 85 | 'Egzaminer\Roll\ExamsGroup', 'indexAction', ]); |
||
| 86 | |||
| 87 | $this->router->map('GET|POST', '/exam/[i:id]', [ |
||
| 88 | 'Egzaminer\Exam\Exam', 'showAction', ]); |
||
| 89 | |||
| 90 | $this->router->map('GET', '/admin', [ |
||
| 91 | 'Egzaminer\Admin\Dashboard', 'indexAction', ]); |
||
| 92 | |||
| 93 | $this->router->map('GET', '/admin/login', [ |
||
| 94 | 'Egzaminer\Admin\Login', 'loginAction', ]); |
||
| 95 | $this->router->map('POST', '/admin/login', [ |
||
| 96 | 'Egzaminer\Admin\Login', 'postLoginAction', ]); |
||
| 97 | |||
| 98 | $this->router->map('GET', '/admin/logout', [ |
||
| 99 | 'Egzaminer\Admin\Logout', 'logoutAction', ]); |
||
| 100 | |||
| 101 | $this->router->map('GET', '/admin/exam/add', [ |
||
| 102 | 'Egzaminer\Exam\ExamAdd', 'addAction', ]); |
||
| 103 | $this->router->map('POST', '/admin/exam/add', [ |
||
| 104 | 'Egzaminer\Exam\ExamAdd', 'postAddAction', ]); |
||
| 105 | |||
| 106 | $this->router->map('GET', '/admin/exam/edit/[i:id]', [ |
||
| 107 | 'Egzaminer\Exam\ExamEdit', 'editAction', ]); |
||
| 108 | $this->router->map('POST', '/admin/exam/edit/[i:id]', [ |
||
| 109 | 'Egzaminer\Exam\ExamEdit', 'postEditAction', ]); |
||
| 110 | |||
| 111 | $this->router->map('GET', '/admin/exam/del/[i:id]', [ |
||
| 112 | 'Egzaminer\Exam\ExamDelete', 'deleteAction', ]); |
||
| 113 | $this->router->map('POST', '/admin/exam/del/[i:id]', [ |
||
| 114 | 'Egzaminer\Exam\ExamDelete', 'postDeleteAction', ]); |
||
| 115 | |||
| 116 | $this->router->map('GET', '/admin/exam/edit/[i:tid]/question/add', [ |
||
| 117 | 'Egzaminer\Question\QuestionAdd', 'addAction', ]); |
||
| 118 | $this->router->map('POST', '/admin/exam/edit/[i:tid]/question/add', [ |
||
| 119 | 'Egzaminer\Question\QuestionAdd', 'postAddAction', ]); |
||
| 120 | |||
| 121 | $this->router->map('GET', '/admin/exam/edit/[i:tid]/question/edit/[i:qid]', [ |
||
| 122 | 'Egzaminer\Question\QuestionEdit', 'editAction', ]); |
||
| 123 | $this->router->map('POST', '/admin/exam/edit/[i:tid]/question/edit/[i:qid]', [ |
||
| 124 | 'Egzaminer\Question\QuestionEdit', 'postEditAction', ]); |
||
| 125 | |||
| 126 | $this->router->map('GET', '/admin/exam/edit/[i:tid]/question/del/[i:qid]', [ |
||
| 127 | 'Egzaminer\Question\QuestionDelete', 'deleteAction', ]); |
||
| 128 | $this->router->map('POST', '/admin/exam/edit/[i:tid]/question/del/[i:qid]', [ |
||
| 129 | 'Egzaminer\Question\QuestionDelete', 'postDeleteAction', ]); |
||
| 130 | |||
| 131 | $match = $this->router->match($this->url); |
||
| 132 | |||
| 133 | try { |
||
| 134 | // call closure or throw 404 status |
||
| 135 | if ($match && is_callable($match['target'])) { |
||
| 136 | call_user_func_array([ |
||
| 137 | new $match['target'][0]($this->container), $match['target'][1], |
||
| 138 | ], $match['params']); |
||
| 139 | } else { |
||
| 140 | throw new Exception('Page not exist! No route match'); |
||
| 141 | } |
||
| 142 | } catch (Exception $e) { |
||
| 143 | if ($this->config['debug']) { |
||
| 144 | echo $e->getMessage(); |
||
| 145 | } else { |
||
| 146 | (new Error($this->container))->showAction(404); |
||
| 147 | } |
||
| 148 | $this->terminate(); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 221 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: