From 29a269c07b0b9341391d4db627a1c61f592c615c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Thu, 8 Oct 2020 11:30:24 +0800 Subject: [PATCH] feat(php): add default !name if exception name couldnt be parsed --- src/parsers/php.service.ts | 10 ++++++++-- test/filetypes/php/functions.vader | 8 +++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/parsers/php.service.ts b/src/parsers/php.service.ts index 1a467c41..db1929f8 100644 --- a/src/parsers/php.service.ts +++ b/src/parsers/php.service.ts @@ -240,12 +240,18 @@ export class PhpParserService private parseExceptions(node: SyntaxNode) { if (node.type === 'throw_statement') { - const exceptionName = node.children + const exception: Record = { 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) { diff --git a/test/filetypes/php/functions.vader b/test/filetypes/php/functions.vader index 1e455c09..a682edf5 100644 --- a/test/filetypes/php/functions.vader +++ b/test/filetypes/php/functions.vader @@ -117,7 +117,8 @@ Expect php (generated comment with @param and @return tags): Given php (function with exceptions being raised in the body):