Closed
Description
The current master branch (which will become Symfony 5) raised the minimum requirement of php to 7.2. That php version introduced a feature called Parameter Type Widening that allows a class to drop parameter type constraints when overriding/implementing a method from a parent class/interface.
This opens up an interesting upgrade path for us: We can add new type-hints to interfaces without breaking implementations that were written against the non-typed version on that interface.
Things to watch out for:
- Start with interfaces and classes without parent.
- Don't add type-hints to contracts interfaces: we need php 7.1 compatibility here!
- You can only add type-hints, not change or remove existing ones.
- Don't add return types. They require a different strategy.
- Consult the docblock to find out if you can add a type-hint. But keep in mind that the docblock might lie to you.
- Adding a type-hint might break code that calls the method: Have a look at the implementations of the interface and their tests to find out what kind of values can be passed to the method right now.
- Check if
null
is a valid value. That case is often forgotten in type-hints. - Adding a
callable
type-hint triggers autoloading if the passed value contains a class reference as string. This is a side-effect that should be considered. - The method might contain now-obsolete type-checks. You may remove them.
- The added type-hints might obsolete
@param
annotations. Remove them if they only contain information that is already reflected by the type-hint and the parameter name. - If you find an implementation or child class that is part of another component, don't upgrade the signature just yet if that components should remain compatible with the 4.4 version of the component you're currently working on.
In order to keep the changes reviewable, we should iterate over the components and open one PR per package.
Components
- Asset – @jschaedl – [Asset] Add type-hints to public interfaces and classes #32202
- BrowserKit – @Simperfit – [BrowserKit] [5.0] Add type-hint to all classes #32280
- Cache – @Simperfit @Tobion – [Cache] [5.0] Add type-hint to the Cache component. #32282 [Cache] finish type-hints #32298
- Config – @jschaedl @Tobion – [Config] Add type-hints to public interfaces and classes #32201 [Config] finish adding parameter types #32286
- Console – @Simperfit – [Console] [5.0] Add all type-hint #32318
- CssSelector – @Simperfit – [CssSelector] [5.0] Add type-hint whenever possible #32328
- Debug – @Matts – [5.0] [Debug] Add parameter type-hints where possible #32217 – has been removed in 5.0
- DependencyInjection – @derrabus – [DependencyInjection] Added type-hints on compiler passes #32238, [DependencyInjection] Add type-hints to interfaces and implementations. #32266, [DependencyInjection][ProxyManagerBridge] Added type-hints to LazyProxy classes and interfaces #32283
- DomCrawler – @Simperfit – [DomCrawler] [5.0] add type-hint whenever possible #32329
- Dotenv – nothing to do here.
- ErrorRender – with return types on branch 4.4 as the component is new
- ErrorHandler – with return types on branch 4.4 as the component is new
- EventDispatcher – @derrabus – [EventDispatcher] Add type-hints to EventDispatcherInterface #31984
- ExpressionLanguage – @Simperfit, @derrabus – [ExpressionLanguage] [5.0] add type-hints whenever possible #32346, [ExpressionLanguage] Add more parameter types #33196
- Filesystem – @smoench – [5.0][Filesystem] add parameter type hints #32247
- Finder – @smoench – [5.0][Finder] add parameter type-hints #32243
- Form – @vudaltsov – [Form] Add parameter type declarations #32237
- HttpClient – has been added in Symfony 4.3 and is probably fine.
- HttpFoundation – @julien57, @azjezz – [HttpFoundation] Add type-hints #32271, [HttpFoundation] Add type-hints #33088
- HttpKernel – @tigitz, @derrabus – [HttpKernel] [5.0] Replace docblocks by type-hints #32276, [HttpKernel] Add more parameter types #33195
- Inflector – nothing to do here.
- Intl – @tigitz – [Intl][5.0] Add parameters type-hints #32525
- Ldap – @Simperfit – [Ldap] [5.0] add type-hint to interface and implementation #32253
- Lock – @Simperfit – [Lock] add type-hint whenever possible #33004
- Mailer – has been added in Symfony 4.3 and is probably fine.
- Messenger – has been added in Symfony 4.1 and is probably fine.
- Mime – has been added in Symfony 4.3 and is probably fine.
- OptionsResolver – @jschaedl – [OptionResolver] Add type-hints to OptionResolver class #32235
- Process – @tigitz – [Process] [5.0] Replace docblocks by type-hints #32273
- PropertyAccess – @jschaedl – [PropertyAccess] Add type-hints to public interfaces and classes #32234
- PropertyInfo – @jschaedl – [PropertyInfo] Add type-hints to public interfaces and classes #32233
- Routing – @derrabus – [Routing] Add type-hints to all public interfaces #32176, [Routing] Add type-hints RequestContext and Route classes. #32181, [Routing] Add more parameter types #33191
- Security/Core – @derrabus – [Security] Added type-hints to auth providers, tokens and voters #32351, [Security] Added type-hints to password encoders #32352, [Security] Added type-hints to user providers #32353
- Security/Csrf – @julien57, @Tobion – [Csrf] Added type-hint for CsrfTokenMangerInterface #32208, [CSRF] add more parameter types #32285
- Security/Http – @andreia – [Security][Http] Add type-hints #32314
- Security/Guard – @thomasbisignani – [Security] [Guard] Added type-hints to AuthenticatorInterface #32254
- Serializer – @Simperfit, @derrabus – [Serializer] [5.0] Add type-hints to serializer interface #32229, [Serializer] Add more parameter types #33185
- Stopwatch – @jschaedl @Tobion – [Stopwatch] Add type-hints for Stopwatch and Section classes #32242
- Templating – @derrabus – [Templating] Added type-hints to all classes #32313
- Translation – @Matts – [5.0] [Translator] Add parameter type-hints where possible #32218
- Validator – @xabbuh, @derrabus – [Validator] add parameter type hints to the Validator component #32264, [Validator] Add more parameter types #33190
- VarDumper – @derrabus – [VarDumper] Add parameter type declarations #33153
- VarExporter – has been added in Symfony 4.2 and is probably fine.
- WebLink – nothing to do here.
- Workflow – @lyrixx – [Workflow] Added parameter typhint where possible #32223
- Yaml – @xabbuh – Add scalar typehints/return types #23262, [Yaml] add some missing type declarations #32761
Bundles
- DebugBundle – @Matts – nothing to do here.
- FrameworkBundle – @derrabus – [FrameworkBundle] Added type declarations where possible #32480
- SecurityBundle - @xabbuh - [SecurityBundle] add parameter type declarations where possible #32778
- TwigBundle - @xabbuh - [TwigBundle] add parameter type declarations where possible #32775
- WebProfilerBundle – @Matts – [5.0] [WebProfilerBundle] Add parameter type-hints where possible #32216
- WebServerBundle – has been removed in 5.0
Bridges
- Doctrine - @xabbuh - [DoctrineBridge] add parameter type declarations where possible #32769
- Monolog – nothing to do here
- PhpUnit – nothing to do: needs to stay compatible with PHP 5.
- ProxyManager – @derrabus – [DependencyInjection][ProxyManagerBridge] Added type-hints to LazyProxy classes and interfaces #32283
- Twig - @xabbuh - [TwigBridge] add parameter type declarations where possible #32774
Metadata
Metadata
Assignees
Labels
No labels