Completed
Push — master ( a60631...6c51f7 )
by Elf
02:53
created

ProfileJsonResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 17 5
1
<?php
2
3
namespace ElfSundae\Laravel\Api\Middleware;
4
5
use Closure;
6
use Illuminate\Http\JsonResponse;
7
8
class ProfileJsonResponse
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @see https://github.com/barryvdh/laravel-debugbar/issues/252#issuecomment-248343762
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     * @param  \Closure  $next
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next)
20
    {
21
        $response = $next($request);
22
23
        if (
24
            $response instanceof JsonResponse &&
25
            app()->bound('debugbar') &&
26
            app('debugbar')->isEnabled() &&
27
            is_object($response->getData())
28
        ) {
29
            $response->setData($response->getData(true) + [
30
                '_debugbar' => app('debugbar')->getData(),
31
            ]);
32
        }
33
34
        return $response;
35
    }
36
}
37