Skip to content

Refactor portability statement into a functional composition #4039

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
merged 1 commit into from
May 30, 2020

Conversation

morozov
Copy link
Member

@morozov morozov commented May 30, 2020

Q A
Type improvement
BC Break no

The current implementation of the portability statement contains quite a lot of code repetition, especially introduced at #4019. The reason is that there's no clear separation of concerns of data fetching and data transformation which is aggravated by the number of possible configurations.

In order to make the code more extensible, the statement is split into a wrapper that fetches the data from the underlying statement and a converter that converts the data. Unlike the current design, the converter is created once per connection and is then reused for all fetches.

The other benefit that the separation of concerns gives is that the converter can be fully unit-tested w/o the need to mock the underlying statement or set up data fixtures.

@morozov morozov force-pushed the refactor-portability-statement branch from b78c2c5 to 21198b7 Compare May 30, 2020 04:51
/**
* Creates a composition of the given set of functions
*
* @param callable ...$functions The functions to compose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are going to have to use https://psalm.dev/docs/annotating_code/type_syntax/callable_types/ to fix the Psalm issue below

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up changing the signature of the array_reduce()'s $callback so that it can handle $carry = null, and now Psalm seems happy.

@morozov morozov force-pushed the refactor-portability-statement branch from 21198b7 to 5fac5cd Compare May 30, 2020 06:53

Verified

This commit was signed with the committer’s verified signature. The key has expired.
marandaneto Manoel Aranda Neto
@morozov morozov force-pushed the refactor-portability-statement branch from 5fac5cd to 7204a7d Compare May 30, 2020 07:01
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"convert" is better naming than "fix" 👌

@morozov morozov added this to the 3.0.0 milestone May 30, 2020
@morozov morozov merged commit 90b68ab into doctrine:3.0.x May 30, 2020
@morozov morozov deleted the refactor-portability-statement branch May 30, 2020 14:43
@morozov morozov self-assigned this May 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants