Issues (12)

src/Helpers/functions.php (1 issue)

1
<?php
2
3
use Illuminate\Support\Facades\URL;
4
use Illuminate\Support\Facades\Route;
5
6
if (! function_exists('isActive')) {
7
    /**
8
     * Set the active class to the current opened menu.
9
     *
10
     * @param  array|string $route
11
     * @param  string       $className
12
     * @return string
13
     */
14
    function isActive($route, $className = 'active'): string
15
    {
16
        if (is_array($route)) {
17
            return in_array(Route::currentRouteName(), $route) ? $className : '';
18
        }
19
        if (Route::currentRouteName() == $route) {
20
            return $className;
21
        }
22
        if (strpos(URL::current(), $route)) {
23
            return $className;
24
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 22 is false. This is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
25
    }
26
}
27