Issues (27)

src/helpers.php (3 issues)

1
<?php
2
3
if (!function_exists('className')) {
4
5
    /**
6
     * Get instance class name without namespace
7
     *
8
     * @param $instance
9
     *
10
     * @return string
11
     */
12
    function className($instance)
13
    {
14
        return (new ReflectionClass($instance))->getShortName();
15
    }
16
17
}
18
19
if (!function_exists('str_to_words')) {
20
    function str_to_words($input)
21
    {
22
        $re = '/(?#! splitCamelCase Rev:20140412)
23
    # Split camelCase "words". Two global alternatives. Either g1of2:
24
      (?<=[a-z])      # Position is after a lowercase,
25
      (?=[A-Z])       # and before an uppercase letter.
26
    | (?<=[A-Z])      # Or g2of2; Position is after uppercase,
27
      (?=[A-Z][a-z])  # and before upper-then-lower case.
28
    /x';
29
        $result = preg_split($re, $input);
30
31
        return implode(" ", $result);
0 ignored issues
show
It seems like $result can also be of type false; however, parameter $pieces of implode() does only seem to accept array, 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

31
        return implode(" ", /** @scrutinizer ignore-type */ $result);
Loading history...
32
    }
33
34
}
35
36
if (!function_exists('studly_to_words')) {
37
    function studly_to_words($text)
38
    {
39
        $data = preg_split('/(?=[A-Z])/', class_basename($text));
40
        return trim(implode(' ', $data));
0 ignored issues
show
It seems like $data can also be of type false; however, parameter $pieces of implode() does only seem to accept array, 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

40
        return trim(implode(' ', /** @scrutinizer ignore-type */ $data));
Loading history...
41
    }
42
}
43
44
if (!function_exists('has_permission')) {
45
    function has_permission(\App\User $user, string $ability): bool
0 ignored issues
show
The type App\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
    {
47
        $userRoles = $user->roles;
48
        $hasPermission = false;
49
50
        foreach ($userRoles as $role) {
51
            foreach ($role->permissions as $permission) {
52
                if ($permission->name == $ability) {
53
                    $hasPermission = true;
54
                    break;
55
                }
56
            }
57
        }
58
59
        return $hasPermission;
60
    }
61
}
62