1 | <?php |
||
32 | class ReflectionMethodFactory extends ReflectorFactory |
||
33 | { |
||
34 | const REFLECTION_OBJECT = ReflectionMethod::class; |
||
35 | |||
36 | /** |
||
37 | * @var PHPNativeReflectionMethod |
||
38 | */ |
||
39 | protected $reflector; |
||
40 | |||
41 | /** |
||
42 | * @var ReflectionMethod |
||
43 | */ |
||
44 | protected $object; |
||
45 | |||
46 | /** |
||
47 | * @var Hashmap |
||
48 | */ |
||
49 | protected $parameters; |
||
50 | |||
51 | /** |
||
52 | * @var TypeParser |
||
53 | */ |
||
54 | protected $typeParser; |
||
55 | |||
56 | /** |
||
57 | * Returns a new ReflectionMethodFactory using the given class and |
||
58 | * method names |
||
59 | * |
||
60 | * @param string $class The classname of the method |
||
61 | * @param string $method The method to reflect |
||
62 | * @return ReflectionMethodFactory |
||
63 | */ |
||
64 | public static function fromName(string $class, string $method) |
||
71 | |||
72 | 29 | public function __construct(PHPNativeReflector $reflector) |
|
78 | |||
79 | /** |
||
80 | * Builds the ReflectionMethod from the provided parameters, |
||
81 | * optionally linking to a parent ReflectionComposite |
||
82 | * |
||
83 | * @param ReflectionComposite $parent The reflector for the class |
||
84 | * this method belongs to |
||
85 | * @return ReflectionMethod |
||
86 | */ |
||
87 | 29 | public function build(?ReflectionComposite $parent = null) |
|
88 | { |
||
89 | 29 | $this->typeParser = new TypeParser($parent); |
|
90 | 29 | $this->accessor->setRawValue('owner', $parent); |
|
91 | 29 | $this->accessor->setRawValue |
|
92 | ( |
||
93 | 29 | 'name', |
|
94 | 29 | $this->reflector->getName() |
|
95 | ); |
||
96 | |||
97 | 29 | $this->initParams(); |
|
98 | |||
99 | 29 | $this->accessor->setRawValue('visibility', |
|
100 | 29 | ($this->reflector->isPublic() ? 'public' |
|
101 | 4 | : ($this->reflector->isProtected() ? 'protected' |
|
102 | 1 | : ($this->reflector->isPrivate() ? 'private' |
|
103 | 29 | : ('')))) |
|
104 | ); |
||
105 | 29 | $this->accessor->setRawValue('scope', |
|
106 | 29 | ($this->reflector->isStatic() ? 'static' : 'dynamic') |
|
107 | ); |
||
108 | 29 | $this->accessor->setRawValue('final', |
|
109 | 29 | $this->reflector->isFinal() |
|
110 | ); |
||
111 | |||
112 | 29 | foreach ($this->reflector->getParameters() as $parameter) |
|
113 | { |
||
114 | 29 | $this->addParameter($parameter); |
|
115 | } |
||
116 | |||
117 | 29 | $this->parseDocComment(['param' => 'addParamAnnotation']); |
|
118 | |||
119 | 29 | return $this->object; |
|
120 | } |
||
121 | |||
122 | /** |
||
123 | * Creates the Method's parameter's property with a fixd list of |
||
124 | * the appropriate size |
||
125 | */ |
||
126 | 29 | protected function initParams() |
|
139 | |||
140 | /** |
||
141 | * Processes a param docblock annotation and uses it to decorate |
||
142 | * a method parameter |
||
143 | * |
||
144 | * @param string $name Unused. Should be 'param' |
||
145 | * @param string $value The annotation value |
||
146 | */ |
||
147 | 29 | protected function addParamAnnotation($name, $value) : void |
|
178 | |||
179 | /** |
||
180 | * Adds a parameter to the method, based on it's native |
||
181 | * ReflectionParameter |
||
182 | * |
||
183 | * @param PHPNativeReflectionParameter $reflect |
||
184 | */ |
||
185 | 29 | protected function addParameter |
|
205 | } |
||
206 | |||
207 |
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..