Completed
Push — master ( 620841...b98b1f )
by Oscar
03:26
created

Error::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 9
nc 3
nop 3
1
<?php
2
3
namespace Folk\Controllers;
4
5
use Psr\Http\Message\ServerRequestInterface as Request;
6
use Psr\Http\Message\ResponseInterface as Response;
7
use Folk\Admin;
8
use Psr7Middlewares\Middleware;
9
10
class Error
11
{
12
    public function __invoke(Request $request, Response $response, Admin $app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
13
    {
14
        $format = Middleware\FormatNegotiator::getFormat($request);
15
        $exception = Middleware\ErrorHandler::getException($request);
16
17
        if (!$exception) {
18
            return $response;
19
        }
20
21
        if ($format === 'json') {
22
            return json_encode([
23
                'error' => $exception->getMessage()
24
            ]);
25
        }
26
27
        return $exception->getMessage();
28
    }
29
}
30