Time has passed, I found a solution
The trick is that you can return @return static
in the comments, which is exactly what you need for PHPStorm to detect the correct class, so lets create a BaseModel
that extends CActiveRecord
and has the correct doc comments
So change class MyClass extends CActiveRecord
with class MyClass extends BaseModel
while using this, now all the class hinting will work :)
<?php
/**
* Extension of the default Yii Active Record class
*
* Edit this class to add custom behaviour to all the models used within the application
*
*/
class BaseModel extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* Uses the class that called the model() by default
* @param string $className active record class name.
* @return static The static model class instance
*/
public static function model($className = null)
{
return parent::model($className !== null ? $className : get_called_class());
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param mixed $pk
* @param string $condition
* @param array $params
* @return static
*/
public function findByPk($pk,$condition='',$params=array())
{
return parent::findByPk($pk,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param string $condition
* @param array $params
* @return static
*/
public function find($condition='',$params=array())
{
return parent::find($condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param string $condition
* @param array $params
* @return static[]
*/
public function findAll($condition='',$params=array())
{
return parent::findAll($condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $pk
* @param string $condition
* @param array $params
* @return static[]
*/
public function findAllByPk($pk,$condition='',$params=array())
{
return parent::findAllByPk($pk,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $attributes
* @param string $condition
* @param array $params
* @return static
*/
public function findByAttributes($attributes,$condition='',$params=array())
{
return parent::findByAttributes($attributes,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $attributes
* @param string $condition
* @param array $params
* @return static[]
*/
public function findAllByAttributes($attributes,$condition='',$params=array())
{
return parent::findAllByAttributes($attributes,$condition,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $sql
* @param array $params
* @return static
*/
public function findBySql($sql,$params=array())
{
return parent::findBySql($sql,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* @param $sql
* @param array $params
* @return static[]
*/
public function findAllBySql($sql,$params=array())
{
return parent::findAllBySql($sql,$params);
}
/**
* This function exists only to help the IDE autodetect the returned class
* This will add a couple of milliseconds with every `with` usage
* @return static
*/
public function with()
{
return call_user_func_array('parent::with', func_get_args());
}
/**
* This function exists only to help the IDE autodetect the returned class
* @return static
*/
public function together()
{
return parent::together();
}
}