Skip to content
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

Improved return type for fluent methods in Context #1162

Merged
merged 1 commit into from
Feb 9, 2020

Conversation

wouterj
Copy link
Contributor

@wouterj wouterj commented Feb 8, 2020

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

While the self return type is true, it is too loose. What is actually returned is $this (i.e. the class extending this abstract class). This means the following code is - strictly spoken - invalid:

$serializationContext = SerializationContext::create()
  ->setSerializeNull(true)
  ->setGroups(['api'])
;

$this->serializer->serialize($subject, 'json', $serializationContext)

As PHP does not have the static return type until PHP 8, I think adding this PHPdoc is the best possible solution to make static analysers and IDEs happy.

@goetas goetas merged commit 8855092 into schmittjoh:master Feb 9, 2020
@goetas
Copy link
Collaborator

goetas commented Feb 9, 2020

thank you!

@wouterj wouterj deleted the patch-2 branch February 9, 2020 10:23
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.

2 participants