To improve Code Inspection for PHPStorm I needed to automatically add all database attributes as @property to my CActiveRecord classes. Additionally it adds all relations and some common used CActiveRecord methods too.
A yii commandline utility. You configure it with your db and run it on your codebase. The result looks something like this:
/* * @property int id * @property string password * @property string name * @property bool active * @property Group group * @property array roles * @method User|CActiveRecord find() */ class User extends CActiveRecord
It automatically extracts the type from the database.. The bool comes from tinyint(1) fields. Group is a has_one relation and roles is a has_many relation.. Also I add some common used CActiveRecord methods there.
Download it from: github
How the code works
- Walk through all files in a "/models/" directory
- Extract the tablename from the tableName() function
- Fetch the database information with yii - and map the database type into phpdoc types
- Extract the relations from the relations() function
- Find the class docstring and delete all @property and @method from there
- Add both above informations as @property
- Add some predefined functions as @method