1

I've started using Flight microframework, but all methods are hidden under the hood (not declared in the Flight class).

How can I configure PHPStorm or should I write new set of rules?

Update: use framework instance doesn't work

I've tried to use framework instance, but has no success — I have internal methods in the suggestion list:

enter image description here

Update: autocomplete implemented in the Flight framework

terales
  • 3,116
  • 23
  • 33
  • 1
    Have you checked the very last section in readme -- this should be the easiest way: https://github.com/mikecao/flight#framework-instance . Otherwise you will have to somehow re-declare `Flight` class and include all methods in there (e.g. fake class with all required methods .. but with empty bodies -- will be used by IDE for code completion) – LazyOne Oct 29 '14 at 09:49
  • Thanks for pointing out this, but this approach don't work either. – terales Oct 29 '14 at 10:10
  • If that does not work (I've made my original suggestion based on their docs only, without looking into code) ... then the only option is to create a fake `Flight` class and declare all require methods there. – LazyOne Oct 29 '14 at 10:30

1 Answers1

2

First of all: I'd suggest to submit new issue on their Issue Tracker asking to provide some sort of helper file (like below).. or implement it in any other way (e.g. via PHPDoc' @method for Flight class -- no helper needed and no changes in the actual code -- just PHPDoc) so that IDE (e.g. PhpStorm or Netbeans) would not complain for non-existing methods and you will have some code completion help from IDE.

Magic is good .. but not when whole interface is based on such magic.


On the actual question, which you can resolve yourself.

You will have to spend some time (half an hour or even less) and create some fake Flight class and put it anywhere in your IDE -- it will be used for code completion only. Yes, IDE may warn you about duplicate classes.. but that inspection can be turned off.

The idea is to create a class and declare all required methods as they should have been done if it would be an ordinary class. To start with (will resolve issues for first code example on their readme):

<?php
class Flight
{
    /**
     * Routes a URL to a callback function.
     *
     * @param string $pattern URL pattern to match
     * @param callback $callback Callback function
     * @param boolean $pass_route Pass the matching route object to the callback
     */
    public static function route($pattern, $callback, $pass_route = false) {}

    /**
     * Starts the framework.
     */
    public static function start() {}
}

Here is how it looks now:

enter image description here

As you can see Flight is underwaved -- IDE says that there is more than one class with such name in this project. Just tell PhpStorm to not to report such cases:

enter image description here


For adding methods to the original class via @method PHPDoc tags:

/**
 * Bla-bla -- class description
 *
 * @method static void route(string $pattern, callback $callback, bool $pass_route = false) Routes a URL to a callback function
 * @method static void start() Starts the framework
 */
class Flight
{
...
}
LazyOne
  • 158,824
  • 45
  • 388
  • 391
  • Where should I add second class? Via include path or add to the project (i'm using composer)? Maybe I should submit pull request to the project? – terales Oct 29 '14 at 12:49
  • Maybe I can add some PHPDoc (or alternative) to the main class for autocomplete? After that I'll submit PR to the project and other devs in my project would enjoy simplicity of the solution. – terales Oct 29 '14 at 12:54
  • 1
    1) Anywhere in the project -- does not matter; If outside of the project, then yes -- reference that folder via `Settings | PHP | Include paths` 2) Yes, you can do that with original `Flight` class -- use `@method` tags -- see updates – LazyOne Oct 29 '14 at 13:04