Symbol   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 72
ccs 16
cts 16
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 6 1
A __toString() 0 3 1
A getLine() 0 3 1
A getFile() 0 3 1
A getName() 0 3 1
A __construct() 0 4 1
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\DependencyGuard\Php;
8
9
use PhpParser\Node\Name;
10
use SplFileInfo;
11
12
class Symbol implements SymbolInterface
13
{
14
    /** @var SplFileInfo */
15
    private $file;
16
17
    /** @var Name */
18
    private $node;
19
20
    /**
21
     * Constructor.
22
     *
23
     * @param SplFileInfo $file
24
     * @param Name        $node
25
     */
26 1
    public function __construct(SplFileInfo $file, Name $node)
27
    {
28 1
        $this->file = $file;
29 1
        $this->node = $node;
30 1
    }
31
32
    /**
33
     * Get the name of the symbol.
34
     *
35
     * @return string
36
     */
37 1
    public function getName(): string
38
    {
39 1
        return $this->node->__toString();
40
    }
41
42
    /**
43
     * Get the path of the file in which the symbol is encountered.
44
     *
45
     * @return string
46
     */
47 1
    public function getFile(): string
48
    {
49 1
        return $this->file->getRealPath();
50
    }
51
52
    /**
53
     * Get the line on which the symbol is encountered.
54
     *
55
     * @return int
56
     */
57 1
    public function getLine(): int
58
    {
59 1
        return $this->node->getLine();
60
    }
61
62
    /**
63
     * Specify data that should be serialized to JSON.
64
     *
65
     * @return array
66
     */
67 1
    public function jsonSerialize(): array
68
    {
69
        return [
70 1
            'name' => $this->getName(),
71 1
            'file' => $this->getFile(),
72 1
            'line' => $this->getLine()
73
        ];
74
    }
75
76
    /**
77
     * Convert the symbol to a string.
78
     *
79
     * @return string
80
     */
81 1
    public function __toString(): string
82
    {
83 1
        return $this->getName();
84
    }
85
}
86