Add strict types.
Potential obstacles:
- Methods that override core code
- Interfaces that retroactively define methods already implemented by core code (this is only used in one place)
- Methods that *theoretically* return strings, but can also return MarkupInterface.
Issue fork xbbcode-3207134
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
cburschkaHm... can I test an issue branch?
Comment #5
cburschkaOkay then!
I'm fairly confident that a test suite should have caught any static compile-time errors, and those should be the only potential problems here.
Solutions to the obstacles mentioned above:
- Use {@inheritdoc} when overriding a core method. This will avoid phpstorm complaining about a missing type parameter that wasn't hinted in the parent method.
- Constructor arguments can be type-hinted freely, because constructors do not inherit signatures from their parent.
- Methods cannot define stricter return types (or looser parameter types) than their parents until PHP 7.4, which added full covariance/contravariance support. However, methods can define return types if their parent does not define one.
- The one interface that retroactively defines core methods now supporesses the phpstorm inspection, and refers to #3050720: [Meta] Implement strict typing in existing code in a @todo.
- The TagElementInterface, which defines methods that can return both strings and MarkupInterface, now defines the return type "mixed", and refers to PHP 8 (which adds string|Stringable) in a @todo.