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

PhpClassInFileInspector   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 58
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B getFullyQualifiedClassName() 0 27 5
A readFile() 0 4 1
A evaluateCode() 0 5 1
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
}