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.
Completed
Push — master ( 66e450...88ddda )
by Constantin
04:08
created

FqnResolver::getLastComponent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\CodeAnalysis\Shared;
7
8
9
class FqnResolver
10
{
11 4
    public function resolveShortClassName($shortName, \ReflectionClass $contextClass)
12
    {
13 4
        if (preg_match_all('#use\s+(?P<uses>[^;]+);#ims', file_get_contents($contextClass->getFileName()), $m)) {
14
15 3
            $firstComponent = $this->getFirstComponent($shortName);
16
17 3
            foreach ($m['uses'] as $fullUse) {
18
19 3
                list($use, $alias) = $this->parseUse($fullUse);
20
21 3
                if ($alias == $firstComponent) {
22 3
                    $withoutFirstComponent = $this->getWithoutFirstComponent($shortName);
23
24 3
                    if ($withoutFirstComponent) {
25 1
                        return $use . '\\' . $withoutFirstComponent;
26
                    } else {
27 2
                        return $use;
28
                    }
29
                }
30
            }
31
        }
32
33 1
        return $contextClass->getNamespaceName() . '\\' . $shortName;
34
    }
35
36 3
    private function parseUse($fullUse)
37
    {
38 3
        if (false !== stripos($fullUse, ' as ')) {
39 2
            list($use, $alias) = explode(' as ', $fullUse);
40
41 2
            $use = trim($use, " ");
42 2
            $alias = trim($alias, " ");
43
        } else {
44 1
            $alias = $this->getLastComponent($fullUse);
45 1
            $use = $fullUse;
46
        }
47
48 3
        return [$use, $alias];
49
    }
50
51 1
    private function getLastComponent($name)
52
    {
53 1
        $parts = explode('\\', $name);
54
55 1
        return $parts[count($parts) - 1];
56
    }
57
58 3
    private function getWithoutFirstComponent($name)
59
    {
60 3
        $parts = explode('\\', $name);
61
62 3
        return implode('\\', array_slice($parts, 1));
63
    }
64
65 3
    private function getFirstComponent($name)
66
    {
67 3
        $parts = explode('\\', $name);
68
69 3
        return $parts[0];
70
    }
71
}