Skip to content

[Validator] Define null return type for Constraint::getDefaultOption() #30869

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

Merged

Conversation

jaikdean
Copy link

@jaikdean jaikdean commented Apr 5, 2019

Q A
Branch? 4.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

The Constraint::getDefaultOption() method is documented with a return type of string, but has no return statement. This behaviour is expected, as the return value is compared against null elsewhere in the code, but the docblock causes problems with static analysis when extending this class.

This PR corrects the documented return type to string|null and adds an explicit return null.

@jaikdean jaikdean changed the title Define null return type for Constraint::getDefaultOption() [Validator] Define null return type for Constraint::getDefaultOption() Apr 5, 2019
@xabbuh xabbuh added this to the 3.4 milestone Apr 5, 2019
@fabpot fabpot changed the base branch from 4.2 to 3.4 April 5, 2019 12:51
@fabpot fabpot force-pushed the fix-constraint-default-option-return-type branch from 354586d to 03987f2 Compare April 5, 2019 12:51
@fabpot
Copy link
Member

fabpot commented Apr 5, 2019

Good catch, thanks @jaikdean.

@fabpot fabpot merged commit 03987f2 into symfony:3.4 Apr 5, 2019
fabpot added a commit that referenced this pull request Apr 5, 2019
…efaultOption() (jaikdean)

This PR was submitted for the 4.2 branch but it was merged into the 3.4 branch instead (closes #30869).

Discussion
----------

[Validator] Define null return type for Constraint::getDefaultOption()

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The `Constraint::getDefaultOption()` method is documented with a return type of `string`, but has no `return` statement. This behaviour is expected, as the return value is compared against `null` elsewhere in the code, but the docblock causes problems with static analysis when extending this class.

This PR corrects the documented return type to `string|null` and adds an explicit `return null`.

Commits
-------

03987f2 Define null return type for Constraint::getDefaultOption()
@jaikdean jaikdean deleted the fix-constraint-default-option-return-type branch April 8, 2019 08:37
fabpot added a commit that referenced this pull request Jun 26, 2019
…lver (Tobion)

This PR was merged into the 4.4 branch.

Discussion
----------

use proper return types in ErrorHandler and ArgumentResolver

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | tiny
| 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 |
| License       | MIT
| Doc PR        |

Found those things while reviewing #31996 which missed some return types due to using `return` instead of `return null`.
It's part of fixing #17201 (due to #10717). See also #30869 that somebody was stumbling over.

Commits
-------

2f9121b use proper return types in ErrorHandler and ArgumentResolver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants