dokuwiki
dokuwiki copied to clipboard
Fix #4235
Fix #4235
Note: This class of problem, i.e. mismatch between documented return values vs. use of them in consumers, is somewhat prevalent and very hard to find unless they happen to trigger a warning or error.
Fixing them as they come up is ok I guess but some sort of automated method to detect these would be great.
This class of problem, [...] some sort of automated method to detect these would be great.
There are two approaches possible:
- stricter typing, eg. explicitly declaring return and parameter types
- using a static code analyzer that understands our type hints
Correct type declarations will not magically fix the problems but the IDE will complain during development and things might break with clearer errors when used. However changing type declarations changes signatures and can cause lots of pain when downstream code extends core code (like plugins etc.) so I'd be wary of introducing type declarations on any public APIs.
Static code analysis is probably the best way. I think phpstan should be able to help with that and I'd be happy to add this to our tool chain. However it will probably complain about a lot of stuff that all needs to be addressed at once. I currently lack the energy to do this but I think it's a good idea, so if you want to prepare a PR, please go ahead.
- stricter typing, eg. explicitly declaring return and parameter types
I think this requires newer versions of PHP. Probably at least 8.0 would be required and I think there were changes to PHP in this area between 8.0 and 8.2 as well. The current support of PHP 7.4 would limit what can be done here. And requiring PHP 8.2 is probably too soon?
In addition while this would be a good start it would not catch mismatches in required returned array keys or their values. PHP has no syntax for declaring complex array structures. Returning class objects might be possible but that would require extensive changes to the code.
so if you want to prepare a PR, please go ahead.
Probably not very soon. I know nothing about PHPStan at the moment.
fixed in #4278