1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Padawan\Domain\Project\Collection; |
4
|
|
|
|
5
|
|
|
use Padawan\Domain\Project\Node\MethodData; |
6
|
|
|
use Padawan\Domain\Project\Node\ClassData; |
7
|
|
|
use Padawan\Domain\Project\Node\InterfaceData; |
8
|
|
|
|
9
|
|
|
class MethodsCollection { |
10
|
|
|
private $methods = []; |
11
|
|
|
/** @property ClassData */ |
12
|
|
|
private $class; |
13
|
|
|
|
14
|
|
|
public function __construct($class) { |
15
|
|
|
$this->class = $class; |
16
|
|
|
} |
17
|
|
|
public function add(MethodData $method) { |
18
|
|
|
$this->methods[$method->name] = $method; |
19
|
|
|
} |
20
|
|
|
public function remove(MethodData $method) { |
21
|
|
|
if (array_key_exists($method->name, $this->methods)) { |
22
|
|
|
unset($this->methods[$method->name]); |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
public function get($name, Specification $spec = null) { |
26
|
|
|
if ($spec === null) { |
27
|
|
|
$spec = new Specification('private', 2, true); |
|
|
|
|
28
|
|
|
} |
29
|
|
View Code Duplication |
if (array_key_exists($name, $this->methods)) { |
|
|
|
|
30
|
|
|
$method = $this->methods[$name]; |
31
|
|
|
if ($spec->satisfy($method)) { |
32
|
|
|
return $method; |
33
|
|
|
} |
34
|
|
|
return null; |
35
|
|
|
} |
36
|
|
|
$parentSpec = new Specification( |
37
|
|
|
$spec->getParentMode(), |
38
|
|
|
$spec->isStatic(), |
39
|
|
|
$spec->isMagic() |
40
|
|
|
); |
41
|
|
|
if ($this->class instanceof ClassData) { |
42
|
|
|
$parent = $this->class->getParent(); |
43
|
|
|
if ($parent instanceof ClassData) { |
44
|
|
|
return $parent->methods->get($name, $parentSpec); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
} |
47
|
|
View Code Duplication |
foreach ($this->class->getInterfaces() as $interface) { |
|
|
|
|
48
|
|
|
if ($interface instanceof InterfaceData) { |
49
|
|
|
$method = $interface->methods->get($name, $parentSpec); |
50
|
|
|
if ($method instanceof MethodData) { |
51
|
|
|
return $method; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
public function all(Specification $spec = null) { |
57
|
|
|
if ($spec === null) { |
58
|
|
|
$spec = new Specification; |
59
|
|
|
} |
60
|
|
|
$methods = []; |
61
|
|
|
foreach ($this->methods AS $method) { |
62
|
|
|
if ($spec->satisfy($method)) { |
63
|
|
|
$methods[$method->name] = $method; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
$parentSpec = new Specification( |
67
|
|
|
$spec->getParentMode(), |
68
|
|
|
$spec->isStatic(), |
69
|
|
|
$spec->isMagic() |
70
|
|
|
); |
71
|
|
|
if ($this->class instanceof ClassData) { |
72
|
|
|
$parent = $this->class->getParent(); |
73
|
|
|
if ($parent instanceof ClassData) { |
74
|
|
|
$parentM = $parent->methods->all($parentSpec); |
|
|
|
|
75
|
|
|
$methods = array_merge( |
76
|
|
|
$parentM, |
77
|
|
|
$methods |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
View Code Duplication |
foreach ($this->class->getInterfaces() as $interface) { |
|
|
|
|
82
|
|
|
if ($interface instanceof InterfaceData) { |
83
|
|
|
$parentM = $interface->methods->all($parentSpec); |
84
|
|
|
$methods = array_merge($parentM, $methods); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
return $methods; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: