I was disappointed by lack of code completion support when using Yii in JetBrains PHPStorm. There’re plenty of requests to add support for magic properties and all things magic both in PhpStorm bug tracker and here on the forum. I can’t wait, I want to develop. So here’s my quick fix.
I’ve written a script which finds PHPDoc comments for getters and setters, then writes text file with comments. It relies on proper existing comments and proper code formatting. Haven’t noticed any problems with the script, but it’s easily breakable. The script is released into public domain.
I’ve decided to use only @property tags, because PHPStorm doesn’t seem to properly support @property-read and @property-write (they’re displayed in code completion, but comment is ignored on Ctrl+Q).
2162
phpdoc-trunk-simple.diff.txt
— diff file for current trunk (rev. 3422)
2163
GenPhpDocProp.php.txt
— script used to generate comments
2164
phpdoc-trunk-simple.txt
— generated file with comments (only @property)
2165
phpdoc-trunk-complex.txt
— generated file with comments (also with @property-read and @property-write)
Please note, PHPStorm decided to force newlines on the end of file and to trim unneceassary whitespace. If that’s a problem with your code committing convention, it should be easy to revert those lines.
I hope to see PHPDoc comments included in the next version and updated as long as it’s necessary. There’re feature requests for PHPStorm which, once implemented, would make this copy-pasting redundant, but that could take a long time.
I’d also like to hear ideas how to include components from application config in code completion. Currently I have to use dirty hacks:
[ index.php ]
/** @return CMyApplication */
function app()
{
return Yii::app();
}
[ intellisense.php ]
/**
* @property CLogRouter $log
*/
class CMyApplication extends CWebApplication{}
Stuff like this (suggested here on th forum) doesn’t seem to work:
[ intellisense.php ]
class Yii extends Yii
{
/** @return CMyApplication */
static public function app(){}
}
But it’s probably related to bugs in PHPStorm which seems to have problems when class is declared in multiple files.
P.S. “You aren’t permitted to upload this kind of file” error for diff files was unexpected…