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   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A __construct() 0 13 1
A registerAutoloader() 0 4 1
A aliasClass() 0 16 3
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