Hinting about database columns to inspections for magic getters/setters

Apologies for the confusing title, but I'm not even sure of what keywords I should be using.

My PHP classes that are associated w/database (PostgreSQL) tables use magic getters and setters to interface w/fields, and I want inspections to recognize them. For instance, if I had a table called "Student" and it's column definitions were:

  • name: int
  • student_id: char(10)
  • email: char(30)

then I would have a class called "Student" and I would insert a record like so:

$table = new Student;
$table->name = $name;
$table->student_id = $student_id;
$table->email = $email;

Of course, PhpStorm is clever enough to recognize that those variables are managed by magic methods, but it would be even better if it could only recognize variable names that are also table names. Is it possible to hint this to PS? I know of something called "Live Templates" but I don't really get them yet.

Running PhpStorm 10.0.3 in Ubuntu 15.10.

Comment actions Permalink

Hi there,

If I understand you correctly then you can use @property in PHPDoc for that class.

Something like this:

* Student class
* @property string $name Student's full name
* @property int $student_id
* ...
class Student {
Comment actions Permalink

Amazing! I didn't think it was going to be possible. It does everything I wanted:

  • Gives a tooltips when mousing over
  • Offers completion
  • Changes context highlighting (although, the colours are too similar to the magic variables, so I'll have to change that. I always fail Ishihara tests badly)

Please sign in to leave a comment.