|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace DependencyAnalyzer\DependencyGraph; |
|
5
|
|
|
|
|
6
|
|
|
use DependencyAnalyzer\DependencyGraph; |
|
7
|
|
|
use DependencyAnalyzer\DependencyGraph\DependencyTypes\Base as DependencyType; |
|
8
|
|
|
use DependencyAnalyzer\DependencyGraph\DependencyTypes\ConstantFetch; |
|
9
|
|
|
use DependencyAnalyzer\DependencyGraph\DependencyTypes\MethodCall; |
|
10
|
|
|
use DependencyAnalyzer\DependencyGraph\DependencyTypes\NewObject; |
|
11
|
|
|
use DependencyAnalyzer\DependencyGraph\DependencyTypes\PropertyFetch; |
|
12
|
|
|
use DependencyAnalyzer\DependencyGraph\FullyQualifiedStructuralElementName as FQSEN; |
|
13
|
|
|
use DependencyAnalyzer\DependencyGraph\FullyQualifiedStructuralElementName\Class_; |
|
14
|
|
|
use Fhaculty\Graph\Edge\Directed; |
|
15
|
|
|
|
|
16
|
|
|
class DependencyArrow |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Directed |
|
20
|
|
|
*/ |
|
21
|
|
|
private $edge; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(Directed $edge) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->edge = $edge; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getDependerName(): string |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->edge->getVertexStart()->getId(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getDependeeName(): string |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->edge->getVertexEnd()->getId(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getDependerClass(): Class_ |
|
39
|
|
|
{ |
|
40
|
|
|
return FQSEN::createClass($this->getDependerName()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getDependeeClass(): Class_ |
|
44
|
|
|
{ |
|
45
|
|
|
return FQSEN::createClass($this->getDependeeName()); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDependencies(): array |
|
49
|
|
|
{ |
|
50
|
|
|
$ret = []; |
|
51
|
|
|
|
|
52
|
|
|
foreach ($this->edge->getAttribute(DependencyGraph::DEPENDENCY_TYPE_KEY) as $dependencyType) { |
|
53
|
|
|
/** @var DependencyType $dependencyType */ |
|
54
|
|
|
if ($dependencyType instanceof MethodCall) { |
|
55
|
|
|
$calleeFQSEN = $this->getDependeeClass()->createMethodFQSEN($dependencyType->getCallee()); |
|
56
|
|
|
|
|
57
|
|
|
$callerFQSEN = !is_null($dependencyType->getCaller()) ? |
|
58
|
|
|
$this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
|
59
|
|
|
$this->getDependerClass(); |
|
60
|
|
|
|
|
61
|
|
|
$ret[] = [$callerFQSEN, $calleeFQSEN]; |
|
62
|
|
|
} elseif ($dependencyType instanceof PropertyFetch) { |
|
63
|
|
|
$calleeFQSEN = $this->getDependeeClass()->createPropertyFQSEN($dependencyType->getPropertyName()); |
|
64
|
|
|
|
|
65
|
|
|
$callerFQSEN = !is_null($dependencyType->getCaller()) ? |
|
66
|
|
|
$this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
|
67
|
|
|
$this->getDependerClass(); |
|
68
|
|
|
|
|
69
|
|
|
$ret[] = [$callerFQSEN, $calleeFQSEN]; |
|
70
|
|
|
} elseif ($dependencyType instanceof ConstantFetch) { |
|
71
|
|
|
$calleeFQSEN = $this->getDependeeClass()->createClassConstantFQSEN($dependencyType->getConstantName()); |
|
72
|
|
|
|
|
73
|
|
|
$callerFQSEN = !is_null($dependencyType->getCaller()) ? |
|
74
|
|
|
$this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
|
75
|
|
|
$this->getDependerClass(); |
|
76
|
|
|
|
|
77
|
|
|
$ret[] = [$callerFQSEN, $calleeFQSEN]; |
|
78
|
|
|
} elseif ($dependencyType instanceof NewObject) { |
|
79
|
|
|
$callerFQSEN = !is_null($dependencyType->getCaller()) ? |
|
80
|
|
|
$this->getDependerClass()->createMethodFQSEN($dependencyType->getCaller()) : |
|
81
|
|
|
$this->getDependerClass(); |
|
82
|
|
|
|
|
83
|
|
|
$ret[] = [$callerFQSEN, $this->getDependeeClass()->createMethodFQSEN('__construct')]; |
|
84
|
|
|
} else { |
|
85
|
|
|
$ret[] = [$this->getDependerClass(), $this->getDependeeClass()]; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
return $ret; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|