2

I have added the custom attribute referral_code of type static to the customer entity. The attribute showing up correctly, and I can get/set it in easy way with $customer->getReferralCode() and with $customer->setReferralCode(value). But these methods, of course, don't really exist inside the Customer Model (I think that behind the scene there is some magic method). The problem is that in this way I don't have any hint/intellisense by IDE. The others developer, if they don't know the existence about the attribute,don't receive any suggestion by theirs IDE. So, it's "normal" that this happen or I can extend the Customer Base Model and add the get/set methods of my custom attributes? If it's possible to do this, what are the steps to reach it?

Mirko Rapisarda
  • 455
  • 5
  • 15

1 Answers1

0

This is not the issue, you are doing it correctly, as you already know these are magic function and it has no definitions of their own. But you can add a description of these function on class-level in comment like this:

/**
 * @method static someClass setReferralCode(int $ref) Description here
 * @method static someClass getReferralCode() Description here
 */
abstract class a {
...

Description here

Reference: https://stackoverflow.com/questions/15634021/how-to-document-magic-call-and-callstatic-methods-for-ides

Shoaib Munir
  • 9,404
  • 10
  • 49
  • 106
  • uhm so this is the best way? It's very "ugly" ahaha. Now another question is: where should I add that comment? Because the Customer model is inside the vendor magento/module-customer, so I can't edit it. If I have a Block class and I need to call the method getReferralCode() I must specify that comment inside my Block class? I have tried it, but it doesn't work (I'm using PHPStorm as IDE). – Mirko Rapisarda Mar 24 '19 at 06:53