Let's say that I have the following code:
$myarray['class1'] = new MyClass();
$myarray['class2'] = new MyOtherClass();
I need to disallow someone from calling a function like this:
$result = $myarray['class1']->myFunction();
Is there any kind of sniff to do so?
To generalize you want to disallow all constructs looking like:
$any_variable_name['any_string_key']->any_method(any_parameters);
Looks doable.
Yes.. That's the general idea.. most of the times the classes that are contained in the array are not Instances of the same Class and this messes autocomplete in many cases. Disallowing this kind of call the user will be enforced to assign the Class to a variable first, like:
/** AnyClass $anyClass */
$anyClass = $any_variable_name['any_string_key'];
$anyClass->any_method(any_parameters);
When you are saying Looks doable are you willing to work on it?
There is no current included sniff to do this. I personally don't have time to work on it
When you are saying Looks doable are you willing to work on it?
Sure. Contact me directly (e.g. over email) if interested.
Thank you for your offer. I have figured this out and I was able at last to create sniff on my own.
Thnx again.
Most helpful comment
Sure. Contact me directly (e.g. over email) if interested.