Conditions | 4 |
Paths | 4 |
Total Lines | 39 |
Code Lines | 31 |
Lines | 28 |
Ratio | 71.79 % |
Changes | 0 |
1 | <?php |
||
32 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
33 | { |
||
34 | $logger = $this->logger; |
||
35 | $response = $next($request, $response); |
||
36 | $uri = $request->getUri()->getPath(); |
||
37 | $statusCode = $response->getStatusCode(); |
||
38 | |||
39 | switch ($statusCode) { |
||
40 | View Code Duplication | case 500: |
|
|
|||
41 | $logger->addCritical('Oops!!! the server got 500 error', [ |
||
42 | 'ip' => $request->getAttribute('ip_address'), |
||
43 | 'uri' => $uri, |
||
44 | 'status' => $statusCode, |
||
45 | ]); |
||
46 | break; |
||
47 | View Code Duplication | case 404: |
|
48 | $logger->addWarning('Someone calling un-existing API action', [ |
||
49 | 'ip' => $request->getAttribute('ip_address'), |
||
50 | 'uri' => $uri, |
||
51 | 'status' => $statusCode, |
||
52 | ]); |
||
53 | break; |
||
54 | View Code Duplication | case 401: |
|
55 | $logger->addWarning('Someone calling API action without access', [ |
||
56 | 'ip' => $request->getAttribute('ip_address'), |
||
57 | 'uri' => $uri, |
||
58 | 'status' => $statusCode, |
||
59 | ]); |
||
60 | break; |
||
61 | View Code Duplication | default: |
|
62 | $logger->addInfo('Someone calling existing API action', [ |
||
63 | 'ip' => $request->getAttribute('ip_address'), |
||
64 | 'uri' => $uri, |
||
65 | 'status' => $statusCode, |
||
66 | ]); |
||
67 | break; |
||
68 | } |
||
69 | return $response; |
||
70 | } |
||
71 | } |
||
72 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.