Skip to content

Commit

Permalink
feat(php): add default !name if exception name couldnt be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed Oct 8, 2020
1 parent dced707 commit 29a269c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/parsers/php.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ export class PhpParserService

private parseExceptions(node: SyntaxNode) {
if (node.type === 'throw_statement') {
const exceptionName = node.children
const exception: Record<string, any> = { name: null };

const name = node.children
.filter((n: SyntaxNode) => n.type === 'object_creation_expression')
.shift()
?.children.filter((n: SyntaxNode) => n.type === 'qualified_name')
.shift()?.text;
this.result.exceptions.push({ name: exceptionName || null });
if (name) {
exception.name = name;
}

this.result.exceptions.push(exception);
}

if (node.childCount > 0) {
Expand Down
8 changes: 5 additions & 3 deletions test/filetypes/php/functions.vader
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ Expect php (generated comment with @param and @return tags):
Given php (function with exceptions being raised in the body):
<?php
function test() {
throw new FirstException('Foo');
$err = new FirstException('Foo');
throw $err;
throw new SecondException('Bar');
}

Expand All @@ -130,12 +131,13 @@ Expect php (generated comment with @param, @throws and @return tags):
/**
* [TODO:description]
*
* @throws FirstException [TODO:description]
* @throws [TODO:name] [TODO:description]
* @throws SecondException [TODO:description]
*
* @return [TODO:type] [TODO:description]
*/
function test() {
throw new FirstException('Foo');
$err = new FirstException('Foo');
throw $err;
throw new SecondException('Bar');
}

0 comments on commit 29a269c

Please sign in to comment.