This is something for regexp lovers 🙂
FLOW3’s Code Convention claim that you should annotate methods that do not return anything with @return void:
/**
* A method
*
* @return void
*/
I keep forgetting it and want to regexp with netbeans for all methods that I’ve missed …
So far i got
\*\s[^@return]+.*(\n)\s.\*/
Which does not work really well:
/**
* Method that gets matched.
*
* @param string $comment
*/
public function aMethod() {
// Some Code
}
/**
* A method that does not get matched and shouldn't.
*
* @param string $test
* @return void
*/
public function anotherMethod($test) {
// Some Code
}
/**
* A variable that get's matched but should not
* be matched.
*
* @var string
*/
protected $var;
/**
* Why is this method getting matched?
*
* @return void
*/
private function thirdMethod() {
// Code
}
How would you match this?
Here’s an example in a regexp tester:
A negative lookbehind assertion might help:
This will match any function which does not have @return as the last line of the docblock. It might have some false positives, i.e. where a @return is there but not on the last line, but it’s a good start.
Note that this doesn’t work in Regex tester because JavaScript doesn’t support the lookbehind assertion. Here’s an example.