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

Error   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 2
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 17 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