|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Padawan\Domain\Scope; |
|
4
|
|
|
|
|
5
|
|
|
use Padawan\Domain\Scope; |
|
6
|
|
|
use Padawan\Domain\Project\FQCN; |
|
7
|
|
|
use Padawan\Domain\Project\Node\Uses; |
|
8
|
|
|
use Padawan\Domain\Project\Node\Variable; |
|
9
|
|
|
use Padawan\Domain\Project\Node\FunctionData; |
|
10
|
|
|
|
|
11
|
|
|
abstract class AbstractScope implements Scope |
|
12
|
|
|
{ |
|
13
|
|
|
private $variables = []; |
|
14
|
|
|
private $functions = []; |
|
15
|
|
|
private $constants = []; |
|
16
|
|
|
/** @var Scope */ |
|
17
|
|
|
private $parent; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** @return Variable[] */ |
|
20
|
|
|
public function getVars() |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->variables; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** @return Variable */ |
|
26
|
|
|
public function getVar($varName) |
|
27
|
|
|
{ |
|
28
|
|
|
if (array_key_exists($varName, $this->variables)) { |
|
29
|
|
|
return $this->variables[$varName]; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function addVar(Variable $var) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->variables[$var->getName()] = $var; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getFunctions() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->functions; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getFunction($functionName) |
|
44
|
|
|
{ |
|
45
|
|
|
if (array_key_exists($functionName, $this->functions)) { |
|
46
|
|
|
return $this->functions[$functionName]; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function addFunction(FunctionData $function) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->functions[$function->name] = $function; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** @return string[] */ |
|
56
|
|
|
public function getConstants() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->constants; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getConstant($constName) |
|
62
|
|
|
{ |
|
63
|
|
|
if (array_key_exists($constName, $this->constants)) { |
|
64
|
|
|
return $this->constants[$constName]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function addConstant($constName) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->constants[$constName] = $constName; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.