My IDE PHPStorm marks next line as mistake (word "password")
Yii::$app->passport->getLoginUrl($Url);
How can i write phpdoc for it.
May be in suchway or how?
/** @var $Yii::$app->passport array */
Yii::$app->passport->getLoginUrl($Url);
You can find the solution for this in Yii 2.0 Cookbook - IDE autocompletion for custom components
Using custom Yii class
The best way to give IDE some hints is to use your own Yii file which isn't actually used when running code. This file could be named
Yii.php
and the content could be the following:
<?php
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
*/
class Yii extends \yii\BaseYii
{
/**
* @var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* @property \app\components\RbacManager $authManager The auth manager for this application. Null is returned if auth manager is not configured. This property is read-only. Extended component.
* @property \app\components\Mailer $mailer The mailer component. This property is read-only. Extended component.
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
*
* @property \app\components\User $user The user component. This property is read-only. Extended component.
* @property \app\components\MyResponse $response The response component. This property is read-only. Extended component.
* @property \app\components\ErrorHandler $errorHandler The error handler application component. This property is read-only. Extended component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*
* @property \app\components\ConsoleUser $user The user component. This property is read-only. Extended component.
*/
class ConsoleApplication extends yii\console\Application
{
}
In the above PHPDoc of
BaseApplication
,WebApplication
,ConsoleApplication
will be used by IDE to autocomplete your custom components described via@property
.Note: To avoid "Multiple Implementations" PHPStorm warning and make autocomplete faster exclude or "Mark as Plain Text"
vendor/yiisoft/yii2/Yii.php
file.That's it. Now
Yii::$app->user
will be our\app\components\User
component instead of default one. The same applies for all other@property
-declared components.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With