Completed
Push — master ( a62439...0f6d12 )
by David
15s queued 11s
created

TrailingSlashUrlGenerator::packageIsDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GNAHotelSolutions\LaravelTrailingSlash\Routing;
4
5
use Illuminate\Routing\UrlGenerator;
6
use Illuminate\Support\Str;
7
8
class TrailingSlashUrlGenerator extends UrlGenerator
9
{
10
    /**
11
     * Format the given URL segments into a single URL.
12
     *
13
     * @param string $root
14
     * @param string $path
15
     * @param string $route
16
     *
17
     * @return string
18
     */
19
    public function format($root, $path, $route = '')
20
    {
21
        if ($this->pathIsFile($path) || $this->packageIsDisabled()) {
22
            return parent::format($root, $path, $route);
0 ignored issues
show
Documentation introduced by
$route is of type string, but the function expects a object<Illuminate\Routing\Route>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23
        }
24
25
        return parent::format($root, $path, $route) . '/';
0 ignored issues
show
Documentation introduced by
$route is of type string, but the function expects a object<Illuminate\Routing\Route>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
    }
27
28
    private function pathIsFile($path): bool
29
    {
30
        return Str::contains(Str::afterLast($path, '/'), '.');
31
    }
32
33
    private function packageIsDisabled(): bool
34
    {
35
        return ! config('laravel-trailing-slash.active', false);
36
    }
37
}
38