Skip to content

Commit eb67a2c

Browse files
committed
fix(php): find exceptions that are preceded by "throw" or end with Exception
1 parent ef073e4 commit eb67a2c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

helper/src/php/parser.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,15 @@ impl<'a> PhpParser<'a> {
308308
.and_then(|node| Some(self.get_node_text(&node)))
309309
.unwrap();
310310

311-
tokens.insert("name".to_string(), Value::String(name));
311+
let prev_sibling_node = &child_node.prev_sibling();
312312

313-
exceptions.push(Value::Object(tokens));
313+
if name.ends_with("Exception") || (prev_sibling_node.is_some() && prev_sibling_node.unwrap().kind() == "throw") {
314+
tokens.insert("name".to_string(), Value::String(name));
315+
}
316+
317+
if !tokens.is_empty() {
318+
exceptions.push(Value::Object(tokens));
319+
}
314320
}
315321

316322
}

test/filetypes/php/functions.vader

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Expect php (generated comment with @param and @return tags):
117117
Given php (function with exceptions being raised in the body):
118118
<?php
119119
function test() {
120+
$user = new User(); // this should be ignored
120121
$err = new FirstException('Foo');
121122
throw $err;
122123
throw new SecondException('Bar');
@@ -137,6 +138,7 @@ Expect php (generated comment with @param, @throws and @return tags):
137138
* @return [TODO:type] [TODO:description]
138139
*/
139140
function test() {
141+
$user = new User(); // this should be ignored
140142
$err = new FirstException('Foo');
141143
throw $err;
142144
throw new SecondException('Bar');

0 commit comments

Comments
 (0)