|
8 | 8 |
|
9 | 9 | namespace yii\apidoc\models; |
10 | 10 |
|
| 11 | +use InvalidArgumentException; |
11 | 12 | use phpDocumentor\Reflection\DocBlock\Tag; |
12 | 13 | use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; |
13 | 14 | use phpDocumentor\Reflection\DocBlock\Tags\Generic; |
|
22 | 23 | use phpDocumentor\Reflection\Php\Property; |
23 | 24 | use phpDocumentor\Reflection\Php\Trait_; |
24 | 25 | use phpDocumentor\Reflection\TypeResolver; |
| 26 | +use RuntimeException; |
25 | 27 | use yii\base\BaseObject; |
26 | 28 | use yii\helpers\StringHelper; |
27 | 29 |
|
@@ -242,51 +244,63 @@ public function __construct($parent = null, $reflector = null, $context = null, |
242 | 244 | $this->templates[(string) $fqsen] = $tag; |
243 | 245 | unset($this->tags[$i]); |
244 | 246 | } elseif ($tag instanceof Generic) { |
245 | | - if ($tag->getName() === self::TODO_TAG_NAME) { |
246 | | - $this->todos[] = $tag; |
247 | | - unset($this->tags[$i]); |
248 | | - } elseif ($tag->getName() === self::PHPSTAN_TYPE_ANNOTATION_NAME) { |
249 | | - $tagData = explode(' ', trim($tag->getDescription()), 2); |
250 | | - $phpStanType = new PseudoTypeDoc( |
251 | | - PseudoTypeDoc::TYPE_PHPSTAN, |
252 | | - $this, |
253 | | - trim($tagData[0]), |
254 | | - $typeResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
255 | | - ); |
256 | | - $fqsen = $fqsenResolver->resolve($phpStanType->name, $this->phpDocContext); |
257 | | - $this->phpStanTypes[(string) $fqsen] = $phpStanType; |
258 | | - unset($this->tags[$i]); |
259 | | - } elseif ($tag->getName() === self::PSALM_TYPE_ANNOTATION_NAME) { |
260 | | - $tagData = explode('=', trim($tag->getDescription()), 2); |
261 | | - $psalmType = new PseudoTypeDoc( |
262 | | - PseudoTypeDoc::TYPE_PSALM, |
263 | | - $this, |
264 | | - trim($tagData[0]), |
265 | | - $typeResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
266 | | - ); |
267 | | - $fqsen = $fqsenResolver->resolve($psalmType->name, $this->phpDocContext); |
268 | | - $this->psalmTypes[(string) $fqsen] = $psalmType; |
269 | | - unset($this->tags[$i]); |
270 | | - } elseif ($tag->getName() === self::PHPSTAN_IMPORT_TYPE_ANNOTATION_NAME) { |
271 | | - $tagData = explode(' from ', trim($tag->getDescription()), 2); |
272 | | - $phpStanTypeImport = new PseudoTypeImportDoc( |
273 | | - PseudoTypeImportDoc::TYPE_PHPSTAN, |
274 | | - trim($tagData[0]), |
275 | | - $fqsenResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
276 | | - ); |
277 | | - $fqsen = $fqsenResolver->resolve($phpStanTypeImport->typeName, $this->phpDocContext); |
278 | | - $this->phpStanTypeImports[(string) $fqsen] = $phpStanTypeImport; |
279 | | - unset($this->tags[$i]); |
280 | | - } elseif ($tag->getName() === self::PSALM_IMPORT_TYPE_ANNOTATION_NAME) { |
281 | | - $tagData = explode(' from ', trim($tag->getDescription()), 2); |
282 | | - $psalmTypeImport = new PseudoTypeImportDoc( |
283 | | - PseudoTypeImportDoc::TYPE_PSALM, |
284 | | - trim($tagData[0]), |
285 | | - $fqsenResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
286 | | - ); |
287 | | - $fqsen = $fqsenResolver->resolve($psalmTypeImport->typeName, $this->phpDocContext); |
288 | | - $this->psalmTypeImports[(string) $fqsen] = $psalmTypeImport; |
289 | | - unset($this->tags[$i]); |
| 247 | + try { |
| 248 | + if ($tag->getName() === self::TODO_TAG_NAME) { |
| 249 | + $this->todos[] = $tag; |
| 250 | + unset($this->tags[$i]); |
| 251 | + } elseif ($tag->getName() === self::PHPSTAN_TYPE_ANNOTATION_NAME) { |
| 252 | + $tagData = explode(' ', trim($tag->getDescription()), 2); |
| 253 | + $phpStanType = new PseudoTypeDoc( |
| 254 | + PseudoTypeDoc::TYPE_PHPSTAN, |
| 255 | + $this, |
| 256 | + trim($tagData[0]), |
| 257 | + $typeResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
| 258 | + ); |
| 259 | + $fqsen = $fqsenResolver->resolve($phpStanType->name, $this->phpDocContext); |
| 260 | + $this->phpStanTypes[(string) $fqsen] = $phpStanType; |
| 261 | + unset($this->tags[$i]); |
| 262 | + } elseif ($tag->getName() === self::PSALM_TYPE_ANNOTATION_NAME) { |
| 263 | + $tagData = explode('=', trim($tag->getDescription()), 2); |
| 264 | + $psalmType = new PseudoTypeDoc( |
| 265 | + PseudoTypeDoc::TYPE_PSALM, |
| 266 | + $this, |
| 267 | + trim($tagData[0]), |
| 268 | + $typeResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
| 269 | + ); |
| 270 | + $fqsen = $fqsenResolver->resolve($psalmType->name, $this->phpDocContext); |
| 271 | + $this->psalmTypes[(string) $fqsen] = $psalmType; |
| 272 | + unset($this->tags[$i]); |
| 273 | + } elseif ($tag->getName() === self::PHPSTAN_IMPORT_TYPE_ANNOTATION_NAME) { |
| 274 | + $tagData = explode(' from ', trim($tag->getDescription()), 2); |
| 275 | + $phpStanTypeImport = new PseudoTypeImportDoc( |
| 276 | + PseudoTypeImportDoc::TYPE_PHPSTAN, |
| 277 | + trim($tagData[0]), |
| 278 | + $fqsenResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
| 279 | + ); |
| 280 | + $fqsen = $fqsenResolver->resolve($phpStanTypeImport->typeName, $this->phpDocContext); |
| 281 | + $this->phpStanTypeImports[(string) $fqsen] = $phpStanTypeImport; |
| 282 | + unset($this->tags[$i]); |
| 283 | + } elseif ($tag->getName() === self::PSALM_IMPORT_TYPE_ANNOTATION_NAME) { |
| 284 | + $tagData = explode(' from ', trim($tag->getDescription()), 2); |
| 285 | + $psalmTypeImport = new PseudoTypeImportDoc( |
| 286 | + PseudoTypeImportDoc::TYPE_PSALM, |
| 287 | + trim($tagData[0]), |
| 288 | + $fqsenResolver->resolve(trim($tagData[1]), $this->phpDocContext) |
| 289 | + ); |
| 290 | + $fqsen = $fqsenResolver->resolve($psalmTypeImport->typeName, $this->phpDocContext); |
| 291 | + $this->psalmTypeImports[(string) $fqsen] = $psalmTypeImport; |
| 292 | + unset($this->tags[$i]); |
| 293 | + } |
| 294 | + } catch (InvalidArgumentException | RuntimeException $e) { |
| 295 | + if ($context !== null){ |
| 296 | + $context->errors[] = [ |
| 297 | + 'line' => $this->startLine, |
| 298 | + 'file' => $this->sourceFile, |
| 299 | + 'message' => 'Exception: ' . $e->getMessage(), |
| 300 | + ]; |
| 301 | + } else { |
| 302 | + throw $e; |
| 303 | + } |
290 | 304 | } |
291 | 305 | } elseif ($tag instanceof InvalidTag && $context !== null) { |
292 | 306 | $exception = $tag->getException(); |
|
0 commit comments