Issues (115)

src/Middleware/AddResponseHeaders.php (1 issue)

Severity
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
The parameter $guard is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

21
    public function handle($request, Closure $next, /** @scrutinizer ignore-unused */ $guard = null)

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

Loading history...
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