autocompletephpstormflightphp

How can I add autocompletion for Flight PHP microframework in PHPStorm


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


Solution

  • 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
    {
    ...
    }