-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[5.0] Add parameter type-hints #32179
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
Comments
…face (derrabus) This PR was merged into the 5.0-dev branch. Discussion ---------- [EventDispatcher] Add type-hints to EventDispatcherInterface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A This PR adds type-hints to `EventDispatcherInterface` to give it a more php7-like feeling. Adding these type-hints on master should not be a breaking change because we require php 7.2 there, which allows downstream classes/interfaces to remove a type-hint from a method signature. Commits ------- 2bc9472 [EventDispatcher] Add type-hints to EventDispatcherInterface.
…bus) This PR was merged into the 5.0-dev branch. Discussion ---------- [Routing] Add type-hints to all public interfaces | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A This PR adds type-hints to all interfaces of the Routing component to give them a more php7-like feeling. Adding these type-hints on master should not be a breaking change because we require php 7.2 there, which allows downstream classes/interfaces to remove a type-hint from a method signature. Notes: * There is also an implementation of `RedirectableUrlMatcherInterface` in the Framework Bundle. I did not upgrade its interface in order to keep the bundle compatible with Routing 4.4. * We could apply similar changes to the `Route`, `RouteCollection` etc. in a follow-up PR. This PR only concentrated on the interfaces and their implementations. Commits ------- 457b322 [Routing] Add type-hints to all public interfaces.
@derrabus , I am ready to help with Form component |
A small reminder: This ticket is about parameter type-hints. Please do not add return types (yet). |
The title is wrong and people copy-paste this: It's not only about scalar types. We also want to add object etc parameter types. |
Fixed |
doing lock when #32198 is merged :). |
Updated the list, looking into DI now. |
…ter types (derrabus) This PR was merged into the 5.0-dev branch. Discussion ---------- [HttpKernel] Bump dependencies and apply upstream parameter types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A This PR bumps some dependencies of the HttpKernel component in order to apply parameter type declarations. Commits ------- aa0fc6f [HttpKernel] Bump dependencies and apply upstream parameter types.
This PR was merged into the 5.0-dev branch. Discussion ---------- [Routing] Add more parameter types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A Commits ------- daf402e [Routing] Add more parameter types.
All right, I think we can close the issue now. Thanks a lot again to everyone who contributed to making the Symfony codebase a type-safer place! 😃 |
…bus) This PR was merged into the 4.4 branch. Discussion ---------- Add types to routing and DI configuration traits. | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | I don't think so. | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | N/A This PR backports the type declarations added to the configurator traits of the Routing and DI components. These traits expose only final methods, so it should be pretty safe to add return types to them. The only scenario I could make up where this change will break something is if a trait is used to override a method: https://3v4l.org/EAsk8 But I doubt that those traits are used that way. On master, we've used the `object` return type for the fluent methods. That type is not available on 4.4 where we have to support php 7.1. I'm using `self` instead. Since the methods are final and thus cannot be overridden, I believe that we shouldn't run into covariance issues here, so `self` should be safe. Commits ------- 1ca30c9 Add types to roting and DI configuration traits.
This PR was merged into the 5.0-dev branch. Discussion ---------- Parameter type leftovers | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A Commits ------- 34eda04 Added more parameter type declarations.
This PR was merged into the 5.0-dev branch. Discussion ---------- Add parameter type declarations to magic methods | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A Commits ------- ec8215c Add parameter type declarations to magic methods.
…l methods and constructors (derrabus) This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Add types to private/final/internal methods and constructors | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | NA/ Commits ------- def0ac7 Add types to private/final/internal methods and constructors.
…hods and constructors (derrabus) This PR was merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Add types to private/final/internal methods and constructors | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | N/A Commits ------- 1978d88 [HttpFoundation] Add types to private/final/internal methods and constructors.
…rnal methods (derrabus) This PR was merged into the 4.4 branch. Discussion ---------- [Cache] Add types to constructors and private/final/internal methods | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | N/A I'm currently preparing a large PR collecting changes like these. However, the changeset for the Cache component was large enough to justify a dedicated PR, imho. Commits ------- 919afd2 [Cache] Add types to constructors and private/final/internal methods.
…hods (Batch I) (derrabus) This PR was squashed before being merged into the 4.4 branch (closes #33519). Discussion ---------- Add types to constructors and private/final/internal methods (Batch I) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | N/A As promised, now a larger batch with the following components: * Asset * BrowserKit * Config * Console * ~~CssSelector~~ * Debug * ~~DomCrawler~~ * DotEnv * ErrorHandler * ErrorRenderer * ExpressionLanguage * ~~Filesystem~~ * ~~Finder~~ Commits ------- 4039b95 Add types to constructors and private/final/internal methods (Batch I)
…hods (Batch II) (derrabus) This PR was squashed before being merged into the 4.4 branch (closes #33709). Discussion ---------- Add types to constructors and private/final/internal methods (Batch II) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #32179, #33228 | License | MIT | Doc PR | N/A Followup to #33519, this time with: * Form * HttpClient * HttpKernel * intl * Ldap * Ldap * Lock * Messenger * Processor * PropertyInfo * Routing * Security * Serializer * Stopwatch * Translation Commits ------- 9378eb4 Add types to constructors and private/final/internal methods (Batch II)
…hods (Batch III) (derrabus) This PR was squashed before being merged into the 4.4 branch (closes #33770). Discussion ---------- Add types to constructors and private/final/internal methods (Batch III) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | #32179, #33228 | License | MIT | Doc PR | N/A Followup to #33709, this time with: * Validator * VarDumper * Workflow * Yaml * all bridges * all bundles That should be the final batch. 😃 Commits ------- 6493902 Add types to constructors and private/final/internal methods (Batch III)
…contracts (derrabus) This PR was merged into the 5.0-dev branch. Discussion ---------- [Contracts] Add parameter type declarations to contracts | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#32179 | License | MIT | Doc PR | N/A This PR proposes to create a php 7.2 version of the contracts that maintains BC with Symfony 4. The PR suggests to bump the contracts version to ~~1.2~~ 2.0 on the master branch. We would still be able to maintain the contracts 1.1 branch on Symfony's 4.4 branch, should we need to patch the current contracts in the future. This move would allow us to add parameter type declarations to existing contracts interfaces and make use of them in Symfony 5. Especially the Translation and EventDispatcher components benefit a lot from this bump, imho. Contracts that will be added on the road to Symfony 6 wouldn't be restricted to the capabilities of php 7.1, which would be another benefit in my opinion. ~~<sup>1</sup> Test currently fail because the translator is called with `null` as translation key. That possibility should be deprecated imho.~~ Commits ------- bf515e1 Add parameter type declarations to contracts.
…ts (derrabus) This PR was merged into the 5.0-dev branch. Discussion ---------- [Contracts] Add parameter type declarations to contracts | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A This PR proposes to create a php 7.2 version of the contracts that maintains BC with Symfony 4. The PR suggests to bump the contracts version to ~~1.2~~ 2.0 on the master branch. We would still be able to maintain the contracts 1.1 branch on Symfony's 4.4 branch, should we need to patch the current contracts in the future. This move would allow us to add parameter type declarations to existing contracts interfaces and make use of them in Symfony 5. Especially the Translation and EventDispatcher components benefit a lot from this bump, imho. Contracts that will be added on the road to Symfony 6 wouldn't be restricted to the capabilities of php 7.1, which would be another benefit in my opinion. ~~<sup>1</sup> Test currently fail because the translator is called with `null` as translation key. That possibility should be deprecated imho.~~ Commits ------- 4de3773 Add parameter type declarations to contracts.
…nterface (Simperfit) This PR was merged into the 5.0-dev branch. Discussion ---------- [Serializer] [5.0] Add type-hints to serializer interface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | symfony#32179 <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | none <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> This PR adds type-hints to the serializer component ;). Commits ------- 68b588c [Serializer] [5.0] Add type-hints to serializer interface
…nal methods (Batch II) (derrabus) This PR was squashed before being merged into the 4.4 branch (closes symfony#33709). Discussion ---------- Add types to constructors and private/final/internal methods (Batch II) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | symfony#32179, symfony#33228 | License | MIT | Doc PR | N/A Followup to symfony#33519, this time with: * Form * HttpClient * HttpKernel * intl * Ldap * Ldap * Lock * Messenger * Processor * PropertyInfo * Routing * Security * Serializer * Stopwatch * Translation Commits ------- 9378eb4 Add types to constructors and private/final/internal methods (Batch II)
…nal methods (Batch I) (derrabus) This PR was squashed before being merged into the 4.4 branch (closes symfony#33519). Discussion ---------- Add types to constructors and private/final/internal methods (Batch I) | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#32179, symfony#33228 | License | MIT | Doc PR | N/A As promised, now a larger batch with the following components: * Asset * BrowserKit * Config * Console * ~~CssSelector~~ * Debug * ~~DomCrawler~~ * DotEnv * ErrorHandler * ErrorRenderer * ExpressionLanguage * ~~Filesystem~~ * ~~Finder~~ Commits ------- 4039b95 Add types to constructors and private/final/internal methods (Batch I)
Uh oh!
There was an error while loading. Please reload this page.
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:
null
is a valid value. That case is often forgotten in type-hints.callable
type-hint triggers autoloading if the passed value contains a class reference as string. This is a side-effect that should be considered.@param
annotations. Remove them if they only contain information that is already reflected by the type-hint and the parameter name.In order to keep the changes reviewable, we should iterate over the components and open one PR per package.
Components
Bundles
Bridges
The text was updated successfully, but these errors were encountered: