0

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?

Bas Leijdekkers
  • 23,709
  • 4
  • 70
  • 68
timo kranz
  • 153
  • 1
  • 2
  • 13
  • What you provide is PHP Code but you talking about intellij (without the s) and this is for Java. If you like to have something for PHP use PhpStorm. There you will have auto completion for PHP https://www.jetbrains.com/phpstorm/features/. I don't thing you can do PHP stuff in intellij-idea – Webdesigner Sep 30 '17 at 23:31
  • Sorry, I didn't mean that. I've adjusted my question. – timo kranz Oct 01 '17 at 08:41

2 Answers2

3

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
chocochaos
  • 1,466
  • 10
  • 15
0

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. enter image description here

Shaunak Sontakke
  • 980
  • 1
  • 7
  • 17