Issues (14)

src/Http/Middleware/RequireXml.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Bmatovu\LaravelXml\Http\Middleware;
4
5
use Bmatovu\LaravelXml\LaravelXml;
6
use Closure;
7
8
class RequireXml
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @see https://stackoverflow.com/a/11973933/2732184
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     * @param bool $isValidXml
17
     *
18
     * @return mixed
19
     */
20 1
    public function handle($request, Closure $next, $isValidXml = false)
21
    {
22 1
        if ('xml' !== $request->getContentTypeFormat()) {
23 1
            return response()->xml(['message' => 'Only accepting content of type XML.'], 415);
24
        }
25
26
        if ($isValidXml && $request->getContent() && ! LaravelXml::is_valid($request->getContent())) {
0 ignored issues
show
The method is_valid() does not exist on Bmatovu\LaravelXml\LaravelXml. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

26
        if ($isValidXml && $request->getContent() && ! LaravelXml::/** @scrutinizer ignore-call */ is_valid($request->getContent())) {
Loading history...
27
            return response()->xml(['message' => 'The given data was malformed.'], 400);
28
        }
29
30
        return $next($request);
31
    }
32
}
33