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.

ShortClassNames::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\TinkerTools;
4
5
use ReflectionClass;
6
7
class ShortClassNames
8
{
9
    /** @var \Illuminate\Support\Collection */
10
    public $classes;
11
12
    public static function register(string $classMapPath = null)
13
    {
14
        $classMapPath = $classMapPath ?? base_path('vendor/composer/autoload_classmap.php');
15
16
        (new static($classMapPath))->registerAutoloader();
17
    }
18
19
    public function __construct(string $classMapPath)
20
    {
21
        $classFiles = include $classMapPath;
22
23
        $this->classes = collect($classFiles)
24
            ->map(function (string $path, string $fqcn) {
25
                $name = last(explode('\\', $fqcn));
26
27
                return compact('fqcn', 'name');
28
            })
29
            ->filter()
30
            ->values();
31
    }
32
33
    public function registerAutoloader()
34
    {
35
        spl_autoload_register([$this, 'aliasClass']);
36
    }
37
38
    public function aliasClass($findClass)
39
    {
40
        $class = $this->classes->first(function ($class) use ($findClass) {
41
            if ($class['name'] !== $findClass) {
42
                return false;
43
            }
44
45
            return ! (new ReflectionClass($class['fqcn']))->isInterface();
46
        });
47
48
        if (! $class) {
49
            return;
50
        }
51
52
        class_alias($class['fqcn'], $class['name']);
53
    }
54
}
55