UrlGenerator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 39
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toRoute() 0 11 2
A to() 0 5 1
1
<?php
2
3
namespace Sulao\LRTS\Routing;
4
5
use Illuminate\Routing\Exceptions\UrlGenerationException;
6
use Illuminate\Routing\Route;
7
use Illuminate\Support\Str;
8
use Sulao\LRTS\Helper;
9
10
class UrlGenerator extends \Illuminate\Routing\UrlGenerator
11
{
12
    /**
13
     * Get the URL for a given route instance.
14
     *
15
     * @param  Route  $route
16
     * @param  mixed  $parameters
17
     * @param  bool  $absolute
18
     * @return string
19
     *
20
     * @throws UrlGenerationException
21
     */
22
    public function toRoute($route, $parameters, $absolute)
23
    {
24
        $url = parent::toRoute($route, $parameters, $absolute);
25
26
        if (Str::endsWith($route->originalUri, '/')) {
0 ignored issues
show
Bug introduced by
It seems like $route->originalUri can also be of type object; however, parameter $haystack of Illuminate\Support\Str::endsWith() 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

26
        if (Str::endsWith(/** @scrutinizer ignore-type */ $route->originalUri, '/')) {
Loading history...
27
            $arr = explode('?', $url);
28
            $arr[0] = Helper::appendSlashes($arr[0], $route->originalUri);
0 ignored issues
show
Bug introduced by
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

28
            $arr[0] = Helper::appendSlashes($arr[0], /** @scrutinizer ignore-type */ $route->originalUri);
Loading history...
29
            $url = implode('?', $arr);
30
        }
31
32
        return $url;
33
    }
34
35
    /**
36
     * Generate an absolute URL to the given path.
37
     *
38
     * @param string    $path
39
     * @param mixed     $extra
40
     * @param bool|null $secure
41
     *
42
     * @return string
43
     */
44
    public function to($path, $extra = [], $secure = null)
45
    {
46
        return Helper::appendSlashes(
47
            parent::to($path, $extra, $secure),
48
            $path
49
        );
50
    }
51
}
52