We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Model fields autocompletion in micro

Hello!

I'm writing api with Micro and use PHPStorm 8.

In nutshell, i have this:

class FoobarModel extends \Phalcon\Mvc\Model {
    public $id;
    public $name;
}
class FoobarController extends \Phalcon\Mvc\Controller {
    public function foobarTest() {
        $foobar = FoobarModel::findFirst(42);
        echo $foobar->name; // No autocompletion )-:
    }
}

I've installed DevTools and framework autocompletion works good.

So, my question is simple: how to autocomplete model fields after finding? findFirst() returns \Phalcon\Mvc\Model instanse and does not show any DocBlocks/fields that in FoobarModel exists.

UPD #1. And what about this:

$foobars = FoobarModel::query()->orderBy('date DESC')->execute();
foreach ($foobars as $foobar)
    echo "$foobar->name\n"; // No autocompletion here too )-:

Do i need to write DockBlocks for every using ORM?

Thanks!



98.9k

How PHPStorm would know that FoobarModel::findFirst(42) returns an instance of FoobarModel without a docblock?



21.7k
edited Oct '14

PHPStorm can't recognize model fields even if i add real fields to class and write docblock for them. Just want to write field docblocks for model to which they belong. And it will work if findFirst() will return instance of my model. I'm newbie to Phalcon and ask how other developers solve this problem.

Writing this every time when i'm using ORM? Seriously?

/** @type FoobarModel $foobar */
$foobar = FoobarModel::findFirst(42);
echo "$foobar->name\n";

And what about foreach by results? Autocomplete works only if i do this:

/** @type FoobarModel[] $foobars */
/** @type FoobarModel $foobar */
$foobars = FoobarModel::find($criteria);
foreach ($foobars as $foobar)
    echo "$foobar->name\n";


98.9k
Accepted
answer

What about put those docblocks in the model so they will be available anywhere?

class FoobarModel extends Model
{
    /** @return FoobarModel */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }
}


21.7k

Thanks for the response!

I'll add then @method to dockblock for my model.

It's tedious, i think, but solves problem, thank you.