Issues (6)

src/Routing/UriValidator.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Sulao\LRTS\Routing;
4
5
use Sulao\LRTS\Helper;
6
7
class UriValidator extends \Illuminate\Routing\Matching\UriValidator
8
{
9
    /**
10
     * Validate a given rule against a route and request.
11
     *
12
     * @param \Illuminate\Routing\Route $route
13
     * @param \Illuminate\Http\Request  $request
14
     *
15
     * @return bool
16
     */
17
    public function matches(
18
        \Illuminate\Routing\Route $route,
19
        \Illuminate\Http\Request $request
20
    ) {
21
        $match = parent::matches($route, $request);
22
23
        if ($match && in_array(Router::$mismatchAction, [404, 301, 302])) {
24
            $pathSlash = Helper::getTrailingSlashes($request->getPathInfo());
25
            $routeSlash = Helper::getTrailingSlashes($route->originalUri);
0 ignored issues
show
It seems like $route->originalUri can also be of type object; however, parameter $path of Sulao\LRTS\Helper::getTrailingSlashes() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

25
            $routeSlash = Helper::getTrailingSlashes(/** @scrutinizer ignore-type */ $route->originalUri);
Loading history...
26
            if ($routeSlash !== $pathSlash) {
27
                if (Router::$mismatchAction == 404) {
28
                    abort(404);
29
                }
30
31
                $uri = $request->getUri();
32
                $arr = explode('?', $uri);
33
                $arr[0] = Helper::appendSlashes($arr[0], $route->originalUri);
0 ignored issues
show
It seems like $route->originalUri can also be of type object; however, parameter $origin of Sulao\LRTS\Helper::appendSlashes() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

33
                $arr[0] = Helper::appendSlashes($arr[0], /** @scrutinizer ignore-type */ $route->originalUri);
Loading history...
34
                $uri = implode('?', $arr);
35
36
                abort(Router::$mismatchAction, '', ['Location' => $uri]);
37
            }
38
        }
39
40
        return $match;
41
    }
42
}
43