Symbol::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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