问题
How can I find the method foo with return type boolean
in my example using PhpStorm's Structural Search?
<?php
class test {
public function hello() {
return true;
}
/**
* @return bool
*/
public function foo(): boolean {
return true;
}
}
$t = new test();
$t->foo();
I've tried the following search template:
class $a$ {
public function $show$(): boolean {
$content$
}
}
Where can I learn more about these code/search templates?
回答1:
I have recently been in contact with JetBrains support about the structural search implementation in PhpStorm. The problem is that it is only partically implemented. Things like return types, inheritance, and more things that make structural search useful are currently not available (the options are there, but grayed out and they do not work).
This makes the number of use cases for structural search extremely limited, you are usually better off using different kinds of searches.
There is an open ticket about this: https://youtrack.jetbrains.com/issue/IDEA-174921
For your use case (finding functions with a boolean return type), I would recommend doing a regular expression search:
- Go to Edit -> Find -> Find in Path.
- Make sure Regex is checked and Match case is unchecked.
- Enter the following regex:
function[^}]+:\s*bool
回答2:
You can do it with this:
class $class_name$ {public function $function_name$(): bool}
OR
Just use bool instead of boolean in the search template that you have.
来源:https://stackoverflow.com/questions/46506157/intellij-structural-search-in-phpstorm-to-find-methods-with-specific-return-type