GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Reflection::firstParameterType()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Menu\Helpers;
4
5
use ReflectionFunction;
6
use ReflectionObject;
7
use ReflectionParameter;
8
use Spatie\Menu\Item;
9
10
class Reflection
11
{
12
    public static function firstParameterType(callable $callable): string
13
    {
14
        $reflection = is_object($callable)
15
            ? (new ReflectionObject($callable))->getMethod('__invoke')
16
            : new ReflectionFunction($callable);
17
18
        $parameters = $reflection->getParameters();
19
20
        $parameterTypes = array_map(function (ReflectionParameter $parameter) {
21
            return $parameter->getClass() ? $parameter->getClass()->name : null;
22
        }, $parameters);
23
24
        return $parameterTypes[0] ?? '';
25
    }
26
27
    public static function itemMatchesType(Item $item, string $type): bool
28
    {
29
        if ($type === '') {
30
            return true;
31
        }
32
33
        return $item instanceof $type;
34
    }
35
}
36