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 ( 59446a...77a017 )
by Constantin
02:32
created

getFullyQualifiedClassName()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 27
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 14
cts 14
cp 1
rs 8.439
c 0
b 0
f 0
cc 5
eloc 14
nc 6
nop 1
crap 5
1
<?php
2
3
4
namespace Gica\CodeAnalysis;
5
6
7
use Gica\FileSystem\FileSystemInterface;
8
use Gica\FileSystem\OperatingSystemFileSystem;
9
10
class PhpClassInFileInspector
11
{
12
    /**
13
     * @var FileSystemInterface
14
     */
15
    private $fileSystem;
16
17 6
    public function __construct(
18
        FileSystemInterface $fileSystem = null
19
    )
20
    {
21 6
        $this->fileSystem = $fileSystem ?? new OperatingSystemFileSystem();
22 6
    }
23
24
    /**
25
     * @param $fullFilePath
26
     * @return null|string
27
     */
28 6
    public function getFullyQualifiedClassName(string $fullFilePath)
29
    {
30 6
        $content = $this->readFile($fullFilePath);
31
32 6
        if (!preg_match('#class\s+(?P<className>\S+)\s#ims', $content, $m)) {
33 3
            return null;
34
        }
35
36 6
        $unqualifiedClassName = $m['className'];
37
38 6
        if (!preg_match('#namespace\s+(?P<namespace>\S+);#ims', $content, $m)) {
39 3
            return null;
40
        }
41
42 6
        $namespace = $m['namespace'];
43 6
        if ($namespace)
44 6
            $namespace = '\\' . $namespace;
45
46
47 6
        $fqn = $namespace . '\\' . $unqualifiedClassName;
48
49 6
        if (!class_exists($fqn)) {
50 3
            $this->evaluateCode($content);
51
        }
52
53 6
        return $fqn;
54
    }
55
56 6
    private function readFile($fullFilePath)
57
    {
58 6
        return $this->fileSystem->fileGetContents($fullFilePath);
59
    }
60
61 3
    private function evaluateCode($content)
62
    {
63 3
        $content = str_replace('<?php', '', $content);
64 3
        eval($content);
65 3
    }
66
67
}