| Conditions | 10 |
| Paths | 10 |
| Total Lines | 35 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| 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 |
||
| 20 | public function handle(Request $request, Closure $next) |
||
| 21 | { |
||
| 22 | $blog = new Blog(); |
||
| 23 | $method = $request->getMethod(); |
||
| 24 | $requestPath = $request->getRequestUri(); |
||
| 25 | $returnArray = array(); |
||
| 26 | $returnStatus = 0; |
||
| 27 | |||
| 28 | |||
| 29 | if ($method == "POST" && $requestPath == "/api/blog") { |
||
| 30 | $name = $request->input("name"); |
||
| 31 | $description = $request->input("description"); |
||
| 32 | $url = $request->input("url"); |
||
| 33 | |||
| 34 | if ($name == null || $description == null || $url == null) { |
||
| 35 | $returnArray["error-code"] = "invalid-request"; |
||
| 36 | $returnStatus = 400; |
||
| 37 | } |
||
| 38 | } else if ($method == "PUT" && $requestPath == "/api/blog") { |
||
| 39 | $hash = $request->input("hash"); |
||
| 40 | $blogResult = $blog->where("hash", $hash)->first(); |
||
| 41 | if ($blogResult == null) { |
||
| 42 | $returnArray["error-code"] = "blog-not-found"; |
||
| 43 | $returnStatus = 404; |
||
| 44 | } |
||
| 45 | } else { |
||
| 46 | $returnArray["error-code"] = "request-not-found"; |
||
| 47 | $returnStatus = 400; |
||
| 48 | } |
||
| 49 | |||
| 50 | if (!empty($returnArray)) { |
||
| 51 | return FormatHelper::formatData($returnArray, false, $returnStatus); |
||
| 52 | } |
||
| 53 | |||
| 54 | return $next($request); |
||
| 55 | } |
||
| 56 | } |