Optional methods in an Interface

I am working with a PHP package that has an interface in it. That interface has certain methods that are required as you would expect from an interface. The interface also has a number a methods, however, that are not required. The people who built this library are documenting the optional methods by putting @method tags in the DocBlock of the interface for each method as if they were being handled by a __call function and then they just put a note saying that they are optional methods. The problem is that PhpStorm is complaining when I implement that interface because I am not implementing the methods that are in the DocBlock but not actually in the interface. When I tell PhpStorm to create the stubs, it just creates @method tags in the DocBlock of my class but I don't really think that is the correct answer since those methods don't actually exist in my class. I have 2 possible solutions:

  1. Is there a way to tell PhpStorm to ignore the @method tags in the interface so I am not getting the error anymore?
  2. Is there a better way to document these optional methods that I could suggest to the creators of that library?

Thanks!

6 comments

> the people who built this library are documenting the optional methods by putting @method tags in the DocBlock of the interface for each method as if they were being handled by a __call function

Do they have an explanation for this?

Is there a way to tell PhpStorm to ignore the @method tags

You can select a line/string with an error > Alt+Enter > left arrow > Disable inspection.

> Is there a better way to document these optional methods that I could suggest to the creators of that library?

Can you link us an explicit example?

0

>Do they have an explanation for this?

I don't really know. Someone brought it up in an issue and one person's response was basically, "Sounds like a PhpStorm issue." I'm not sure what that person's relationship is with the project though. I think they are just trying to create a way to document the methods that can be used in a class that implements the interface in a way that IDE's or other documentation parsers can understand without actually requiring the concrete class to implement the method.

>You can select a line/string with an error > Alt+Enter > left arrow > Disable inspection.

That's exactly what I would like to be able to do but when I hit Alt+Enter, the only option that comes up is to create stubs.

>Can you link us an explicit example?

Here is the link to the actual interface that I am talking about on Github:

https://github.com/thephpleague/omnipay-common/blob/master/src/Omnipay/Common/GatewayInterface.php

0

Hm, what IDE version are you running? Could you please check the same project in EAP build?

I don't really see any errors with coupe of files used in this project

0

I am running 2016.3. The EAP build does give the same error. The error is not necessarily in any of the files in that project but it shows up in projects that use the omnipay-common project. An example of that can be seen at https://github.com/caswell-wc/omnipay-plugnpay/blob/master/src/Gateway.php

0

Yes, I am aware of those issues and I agree with the conclusion. My purpose in creating this post was to figure out if there was a way to get around this. I have been able to see now that there is an option for suppressing that inspection which seems like it maybe the best option at this point but I was also hoping that someone might have an alternative method for documenting these methods in a way that the documentation can be parsed by the IDE but not seen as a method that has to be implemented through the __call method.

0

Please sign in to leave a comment.