Editor PHP Libraries and PHPStorm

Editor PHP Libraries and PHPStorm

dclar43dclar43 Posts: 47Questions: 13Answers: 2

I'm looking into using Editor on my current project with PHPStorm as my IDE. I've been unable to get PHPStorm to 'register' Editor's classes and methods as seen here:

Does anyone have a solution or idea of how to address this?

Answers

  • allanallan Posts: 63,725Questions: 1Answers: 10,506 Site admin

    Rather than using className::inst() could you try new className() - e.g.:

    new Editor( $db, "DBHere" )
        ->fields( ... )
    

    The ::inst static factory method is for compatibility with PHP 5.3 - 5.4 introduced the ability to chain from the constructor and it looks like PHPStorm might not be resolving that.

    Thanks,
    Allan

  • dclar43dclar43 Posts: 47Questions: 13Answers: 2
    edited September 2015

    Thanks for the reply Allan. Your reply got me on the right track. Your solution didn't work unfortunately but the following did initially address the problem.

    $editor = DataTables\Editor::inst($db, "masks");
    $editor->fields();
    

    However it failed to resolve the issue when it occurred chaining more than once. In this case the following snippet of code would still throw the original warning for getFormatter and setFormatter.

        $editor = DataTables\Editor::inst($db, "DBHere");
        $editor->fields(
                    ...
            Field::inst( 'start_date' )
                ->validator( 'Validate::dateFormat', array(
                    "format"  => Format::DATE_ISO_8601,
                    "message" => "Please enter a date in the format yyyy-mm-dd"
                ) )
                ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
                ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
        );
    

    The above solution made me realize the (obvious) source is likely the PHPDoc block associated with Ext::inst(). Since Ext::inst uses reflection PHPStorm can't automatically determine the return type. The PHPDoc block for Ext::inst() originally read

        /**
         * Static method to instantiate a new instance of a class (shorthand of 
         * 'instantiate').
         *
         * This method performs exactly the same actions as the 'instantiate'
         * static method, but is simply shorter and easier to type!
         *  @return Instantiated class
         *  @static
         */
    

    The issue is this line:
    * @return Instantiated class

    phpDocumentor is usually considered to be the default standard for PHPDoc blocks and PHPStorm uses that standard. According to their documentation @return's first parameter is the return type and the second is the description.

    The problem line seems to only have a description. I was able to address this in the following 3 ways:

    1. Removing the line

    2. Replacing the line with:
      * @return mixed Instantiated class

    3. Replacing the line with:
      * @return \DataTables\Editor\Field|\DataTables\Editor\Join|\DataTables\Editor\Upload Instantiated class

  • allanallan Posts: 63,725Questions: 1Answers: 10,506 Site admin

    Thanks very much for looking into this further. I had no idea PHPStorm actually used the doc comments. I'll sort that out for the next release!

    Regards,
    Allan

  • dclar43dclar43 Posts: 47Questions: 13Answers: 2

    Not a problem. Is there a method for reporting this kind of thing? Lot's of warnings and a couple errors popping up in PHPStorm, all superficial, that I'd be interested in addressing if I do end up going with Editor.

    Also I realized that the 3rd solution posted above didn't cover ->process() in this example:

    Editor::inst($db, "DBHere")->fields(
        Field::inst( 'start_date' )
            ->validator( 'Validate::dateFormat', array(
                "format"  => Format::DATE_ISO_8601,
                "message" => "Please enter a date in the format yyyy-mm-dd"
            ) )
            ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
            ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
    )
    ->process($_POST)
    ->json();
    

    updating the PHPDoc line to
    * @return DataTables\Editor|\DataTables\Editor\Field|\DataTables\Editor\Join|\DataTables\Editor\Upload Instantiated class
    addresses that.

    Also, Github Markdown apparently doesn't allow escaping the mention(@) character properly so ```php * @return`;`` shows up as

     * @return
    

    So if some of the formatting in these code blocks looks weird, that's why.

  • allanallan Posts: 63,725Questions: 1Answers: 10,506 Site admin
    edited September 2015

    Is there a method for reporting this kind of thing?

    Yes, here in the forum as you have done. I suspect there are a few doc comments errors. I'll see if I can find a linter for them.

    Allan

This discussion has been closed.