| Conditions | 11 |
| Paths | 40 |
| Total Lines | 47 |
| 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 |
||
| 87 | public function render() |
||
| 88 | { |
||
| 89 | if (Sapi::isCli() && Config::get('environment') == 'production') { |
||
| 90 | $suffix = 'CliAction'; |
||
| 91 | $action = $this->request->fromCli()->get('action', 'index'); |
||
| 92 | } else { |
||
| 93 | |||
| 94 | $suffix = 'Action'; |
||
| 95 | |||
| 96 | if ($this->request->getMethod() != 'GET' && $this->request->getMethod() != 'POST') { |
||
| 97 | |||
| 98 | $redirectUrl = new Value($this->env->REDIRECT_URL); |
||
| 99 | $redirectUrl = $redirectUrl->deleteLeading('/')->deleteTrailing('/')->explode('/'); |
||
| 100 | $action = isset($redirectUrl[1]) ? $redirectUrl[1] : 'index'; |
||
| 101 | |||
| 102 | } else { |
||
| 103 | $bag = sprintf('from%s', ucfirst(strtolower($this->request->getMethod()))); |
||
| 104 | $action = $this->request->{$bag}()->get('action', 'index'); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (Config::get('app.routeable') === true && $this->router instanceof \Pimf\Router) { |
||
| 108 | |||
| 109 | $target = $this->router->find(); |
||
| 110 | |||
| 111 | if ($target instanceof \Pimf\Route\Target) { |
||
| 112 | |||
| 113 | $action = $target->getAction(); |
||
| 114 | |||
| 115 | Request::$getData = new Param( |
||
| 116 | array_merge($target->getParams(), Request::$getData->getAll()) |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | $action = strtolower($action) . $suffix; |
||
| 123 | |||
| 124 | if (method_exists($this, 'init')) { |
||
| 125 | call_user_func(array($this, 'init')); |
||
| 126 | } |
||
| 127 | |||
| 128 | if (!method_exists($this, $action)) { |
||
| 129 | throw new Bomb("no action '{$action}' defined at controller " . get_class($this)); |
||
| 130 | } |
||
| 131 | |||
| 132 | return call_user_func(array($this, $action)); |
||
| 133 | } |
||
| 134 | |||
| 151 |