1 | <?php |
||
2 | |||
3 | namespace VGirol\JsonApi\Middleware; |
||
4 | |||
5 | use Closure; |
||
6 | use Illuminate\Support\Facades\Log; |
||
7 | use Illuminate\Support\Str; |
||
8 | use VGirol\JsonApi\Messages\Messages; |
||
9 | |||
10 | class AddResponseHeaders |
||
11 | { |
||
12 | /** |
||
13 | * Handle an incoming request. |
||
14 | * |
||
15 | * @param \Illuminate\Http\Request $request |
||
16 | * @param \Closure $next |
||
17 | * @param string|null $guard |
||
18 | * |
||
19 | * @return mixed |
||
20 | */ |
||
21 | public function handle($request, Closure $next, $guard = null) |
||
0 ignored issues
–
show
|
|||
22 | { |
||
23 | $response = $next($request); |
||
24 | |||
25 | if (!$response->isEmpty()) { |
||
26 | $mediaType = config('jsonapi.media-type'); |
||
27 | |||
28 | if ($response->headers->has('Content-Type')) { |
||
29 | $header = $response->headers->get('Content-Type'); |
||
30 | if (!Str::contains($header, $mediaType)) { |
||
31 | Log::warning( |
||
32 | sprintf(Messages::ERROR_CONTENT_TYPE_HEADER_ALLREADY_SET, $mediaType) |
||
33 | ); |
||
34 | } |
||
35 | $headers = explode(';', $header); |
||
36 | if (count($headers) > 1) { |
||
37 | Log::warning( |
||
38 | sprintf(Messages::ERROR_CONTENT_TYPE_HEADER_WITHOUT_PARAMETERS, $mediaType) |
||
39 | ); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | $response->header('Content-Type', $mediaType); |
||
44 | } |
||
45 | |||
46 | return $response; |
||
47 | } |
||
48 | } |
||
49 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.