1 | <?php |
||
33 | class ReflectionMethodFactory extends ReflectorFactory |
||
34 | { |
||
35 | const REFLECTION_OBJECT = ReflectionMethod::class; |
||
36 | |||
37 | /** |
||
38 | * @var PHPNativeReflectionMethod |
||
39 | */ |
||
40 | protected $reflector; |
||
41 | |||
42 | /** |
||
43 | * @var ReflectionMethod |
||
44 | */ |
||
45 | protected $object; |
||
46 | |||
47 | /** |
||
48 | * @var Hashmap |
||
49 | */ |
||
50 | protected $parameters; |
||
51 | |||
52 | /** |
||
53 | * @var TypeParser |
||
54 | */ |
||
55 | protected $typeParser; |
||
56 | |||
57 | /** |
||
58 | * Returns a new ReflectionMethodFactory using the given class and |
||
59 | * method names |
||
60 | * |
||
61 | * @param string $class The classname of the method |
||
62 | * @param string $method The method to reflect |
||
63 | * @return ReflectionMethodFactory |
||
64 | */ |
||
65 | public static function fromName(string $class, string $method) |
||
72 | |||
73 | 21 | public function __construct(PHPNativeReflector $reflector) |
|
79 | |||
80 | /** |
||
81 | * Builds the ReflectionMethod from the provided parameters, |
||
82 | * optionally linking to a parent ReflectionComposite |
||
83 | * |
||
84 | * @param ReflectionComposite $parent The reflector for the class |
||
85 | * this method belongs to |
||
86 | * @return ReflectionMethod |
||
87 | */ |
||
88 | 21 | public function build(?ReflectionComposite $parent = null) |
|
89 | { |
||
90 | 21 | $this->typeParser = new TypeParser($parent); |
|
91 | 21 | $this->accessor->setRawValue('owner', $parent); |
|
92 | 21 | $this->accessor->setRawValue |
|
93 | ( |
||
94 | 21 | 'name', |
|
95 | 21 | $this->reflector->getName() |
|
96 | ); |
||
97 | |||
98 | 21 | $this->initParams(); |
|
99 | |||
100 | 21 | $this->accessor->setRawValue('visibility', |
|
101 | 21 | ($this->reflector->isPublic() ? 'public' |
|
102 | 2 | : ($this->reflector->isProtected() ? 'protected' |
|
103 | : ($this->reflector->isPrivate() ? 'private' |
||
104 | 21 | : ('')))) |
|
105 | ); |
||
106 | 21 | $this->accessor->setRawValue('scope', |
|
107 | 21 | ($this->reflector->isStatic() ? 'static' : 'dynamic') |
|
108 | ); |
||
109 | 21 | $this->accessor->setRawValue('final', |
|
110 | 21 | $this->reflector->isFinal() |
|
111 | ); |
||
112 | |||
113 | 21 | foreach ($this->reflector->getParameters() as $parameter) |
|
114 | { |
||
115 | 21 | $this->addParameter($parameter); |
|
116 | } |
||
117 | |||
118 | 21 | $type = $this->reflector->getReturnType(); |
|
119 | 21 | if ($type) |
|
120 | { |
||
121 | $this->accessor->setRawValue |
||
122 | ( |
||
123 | 'nativeReturnType', |
||
124 | !$type->isBuiltin() ? '\\' . $type : (string)$type |
||
125 | ); |
||
126 | } |
||
127 | |||
128 | 21 | $this->parseDocComment(['param' => 'addParamAnnotation']); |
|
129 | |||
130 | 21 | return $this->object; |
|
131 | } |
||
132 | |||
133 | /** |
||
134 | * Creates the Method's parameter's property with a fixd list of |
||
135 | * the appropriate size |
||
136 | */ |
||
137 | 21 | protected function initParams() |
|
150 | |||
151 | /** |
||
152 | * Processes a param docblock annotation and uses it to decorate |
||
153 | * a method parameter |
||
154 | * |
||
155 | * @param string $name Unused. Should be 'param' |
||
156 | * @param string $value The annotation value |
||
157 | */ |
||
158 | 21 | protected function addParamAnnotation($name, $value) : void |
|
189 | |||
190 | /** |
||
191 | * Adds a parameter to the method, based on it's native |
||
192 | * ReflectionParameter |
||
193 | * |
||
194 | * @param PHPNativeReflectionParameter $reflect |
||
195 | */ |
||
196 | 21 | protected function addParameter |
|
216 | } |
||
217 | |||
218 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..