|
11 | 11 | use Hal\Component\OOP\Reflected\MethodUsage; |
12 | 12 | use Hal\Component\OOP\Reflected\ReflectedArgument; |
13 | 13 | use Hal\Component\OOP\Reflected\ReflectedMethod; |
| 14 | +use Hal\Component\OOP\Reflected\ReflectedReturn; |
| 15 | +use Hal\Component\OOP\Resolver\TypeResolver; |
14 | 16 | use Hal\Component\Token\TokenCollection; |
15 | 17 |
|
16 | 18 |
|
@@ -105,7 +107,7 @@ public function extract(&$n, TokenCollection $tokens) |
105 | 107 | $this->extractDependencies($method, $n, $tokens); |
106 | 108 |
|
107 | 109 | // returns |
108 | | - $this->extractReturns($method, $method->getContent()); |
| 110 | + $this->extractReturns($method, $p = $start, $tokens); |
109 | 111 |
|
110 | 112 | // usage |
111 | 113 | $this->extractUsage($method); |
@@ -214,13 +216,28 @@ private function extractDependencies(ReflectedMethod $method, $n, TokenCollectio |
214 | 216 | * Extract the list of returned values |
215 | 217 | * |
216 | 218 | * @param ReflectedMethod $method |
217 | | - * @param string $content |
218 | 219 | * @return $this |
219 | 220 | */ |
220 | | - private function extractReturns(ReflectedMethod $method, $content) { |
221 | | - if(preg_match_all('!([\s;]return\s|^return\s)!', $content, $matches)) { |
| 221 | + private function extractReturns(ReflectedMethod $method, $n, TokenCollection $tokens) { |
| 222 | + |
| 223 | + $resolver = new TypeResolver(); |
| 224 | + |
| 225 | + // PHP 7 |
| 226 | + // we cannot use specific token. The ":" delimiter is a T_STRING token |
| 227 | + $following = $this->searcher->getUnder(array('{'), $n, $tokens); |
| 228 | + if(preg_match('!:(.*)!', $following, $matches)) { |
| 229 | + $type = trim($matches[1]); |
| 230 | + $return = new ReflectedReturn($type, ReflectedReturn::VALUE_UNKNOW, ReflectedReturn::STRICT_TYPE_HINT); |
| 231 | + $method->pushReturn($return); |
| 232 | + return $this; |
| 233 | + } |
| 234 | + |
| 235 | + // array of available values based on code |
| 236 | + if(preg_match_all('![\s;]return\s|^return\s(.*)!', $method->getContent(), $matches)) { |
222 | 237 | foreach($matches[1] as $m) { |
223 | | - $method->pushReturn($m); |
| 238 | + $value = trim($m, ";\t\n\r\0\x0B"); |
| 239 | + $return = new ReflectedReturn($resolver->resolve($m), $value, ReflectedReturn::ESTIMATED_TYPE_HINT); |
| 240 | + $method->pushReturn($return); |
224 | 241 | } |
225 | 242 | } |
226 | 243 | return $this; |
|
0 commit comments