-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Negotiator::getBest() return type hint? #89
Comments
Maybe just change the |
Just came across this with |
I am not quite sure what you're talking about to be honest (phpstan wasn't a thing when I was writing PHP..) but I'd be happy to see these issues fixed. |
This issue occurs because of the following:
I think this can be solved by refactoring the inheritance of the project. I'll take a look into it when I've got a bit of time. Edit: in fact, this can be fixed really easily by providing a more accurate return type in the doc blocks, but I think the project would benefit from some simple OO refactoring. |
This is for willdurand#89 - to ensure correct type hints are provided to developers who use IDEs.
Fixes willdurand#89 - IDEs and PHPStan are happy with this implementation
* Depend on PHPUnit for development In order to run the unit tests, PHPUnit is a hard dev dependency, so I've included it in this commit, and now I can run the unit tests as part of this PR. * Depend on PHPStan for development This is for willdurand#89 - to ensure correct type hints are provided to developers who use IDEs. * Fix object model of AcceptHeader interface Fixes willdurand#89 - IDEs and PHPStan are happy with this implementation * Correct return type * Correct nonexistent Priority class to AcceptHeader * Improve typehint - allow looser type to be returned * Improve typehint - more accurate types as parameters * Improve typehint - more accurate generics as parameters * Expose script property - was only ever written * Properly typehint associative array * Typehint nullable string * Match typehints of parent method * Add PHPStan to CI * Configure PHPUnit versions for different PHP runtimes * Use real phpunit
* Depend on PHPUnit for development In order to run the unit tests, PHPUnit is a hard dev dependency, so I've included it in this commit, and now I can run the unit tests as part of this PR. * Depend on PHPStan for development This is for willdurand#89 - to ensure correct type hints are provided to developers who use IDEs. * Fix object model of AcceptHeader interface Fixes willdurand#89 - IDEs and PHPStan are happy with this implementation * Correct return type * Correct nonexistent Priority class to AcceptHeader * Improve typehint - allow looser type to be returned * Improve typehint - more accurate types as parameters * Improve typehint - more accurate generics as parameters * Expose script property - was only ever written * Properly typehint associative array * Typehint nullable string * Match typehints of parent method * Add PHPStan to CI * Configure PHPUnit versions for different PHP runtimes * Use real phpunit
An easy fix would be to just add every public method of It would solve the issue without introducing any BC. |
The AbstractNegotiator::getBest method returns AcceptHeader interface, that doesn't prescribe any methods so you (as a user of the library) don't know what to call next and you have to rely on looking into implementation details or documentation to know that you can call getType on that. I.e. this isn't about static analysis or phpstan but rather the flawed interface of the library and it hurts its usage even when no static analysis tools are involved. I indeed was puzzled when using the lib on Friday and was like: AcceptHeader interface and now what. You should pull the methods shapes to the interface or maybe type-hint the getBest method to be returning a BaseAccept class instead of the interface. What is the interface for anyway? |
To get offline source inspection (phan, Php Storm, etc.) currently I have to manually type-hint the return-type of
getBest()
inline - for example:Without the
@var
annotation, theif
-statement will fail inspection, because the return-type ofgetBest()
was declared asAcceptHeader
rather thanAccept
, which appears to be the actual return-type.What's the purpose of the empty
AcceptHeader
interface?The text was updated successfully, but these errors were encountered: