Gert-dev / php-ide-serenata

Atom IDE package that integrates the Serenata server to provide PHP code assistance
https://serenata.gitlab.io/
Other
275 stars 19 forks source link

Type-hint global/local unknown variables with inline DockBlock #463

Closed nelson6e65 closed 5 years ago

nelson6e65 commented 5 years ago

I would like to set the type of unknow variables to use autocomplete and other features of Serenata.

For example:

// file_a.php
$errors = new MessageBag();

include('file_b.php');
// file_b.php
if ($errors) {
    $errors->has('key');
}

In this case Serenata can't detect the type of $errors in file_b.php.

But I would like to set the type of $errors variable explicitly with a DocBlock, in order to "tell" to Serenata that I know what type is and I want to "help" her:

// file_b.php

/** @var MessageBag $errors*/
if ($errors) {
    $errors->has('key');
   // ...
}

Or maybe a decorator in DocBlock, like:

// @serenata MessageBag $errors

$errors->has('key');
nelson6e65 commented 5 years ago

Never mind. I located more information in the GitLab Wiki :sweat_smile: topic: Type Override Annotations