Skip to content

Strict typing in Doctrine\ORM, disconnect Doctrine\Common#7130

Closed
Majkl578 wants to merge 13 commits intodoctrine:masterfrom
Majkl578:dev/strict-types
Closed

Strict typing in Doctrine\ORM, disconnect Doctrine\Common#7130
Majkl578 wants to merge 13 commits intodoctrine:masterfrom
Majkl578:dev/strict-types

Conversation

@Majkl578
Copy link
Contributor

@Majkl578 Majkl578 commented Mar 14, 2018

Initial round of strict typing.

  • Disconnected Doctrine\Common persistence for now to allow typehinting changes and Doctrine\Persistence migration.
  • Typehints for classes in the root Doctrine\ORM namespace.
  • Conflict to prophecy versions without PHP 7.2 support (to be dropped in future).

TODO

  • document signature changes - @Ocramius can you please suggest some format? Maybe outside UPGRADE to keep it clean, i.e. something like UPGRADE-STRICT-API.md with diff-like list of changes.
  • squash?

@Majkl578 Majkl578 added this to the 3.0 milestone Mar 14, 2018
@Majkl578 Majkl578 requested a review from Ocramius March 14, 2018 04:36
@Majkl578 Majkl578 force-pushed the dev/strict-types branch 3 times, most recently from fd6c6c9 to ac31815 Compare March 14, 2018 05:01
* {@inheritDoc}
*/
public function createQuery($dql = '') : Query
public function createQuery(string $dql = '') : Query
Copy link
Member

Choose a reason for hiding this comment

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

While introducing BC breaks for the next major release, should we keep the default empty string? Does it make sense to have that? Or is this part of a later discussion?

Copy link
Contributor Author

@Majkl578 Majkl578 Mar 14, 2018

Choose a reason for hiding this comment

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

Adding parameter type is not a BC break.
At this time I don't want to change logic or accepted types too much where not needed, otherwise the PR(s) would be pain to review. That's also why I i.e. didn't improve typing for QueryBuilder and parameter binding/types in general.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right. Type widening in PHP 7.2. PHP 7.2 will be minimum version. I totally forgot that.

},
"conflict": {
"phpspec/prophecy": "<1.7.5"
},
Copy link

Choose a reason for hiding this comment

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

You are blocking potential users of prophecy < 1.7.5 even if they don't intend to test doctrine

Copy link

Choose a reason for hiding this comment

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

So instead of how requiring it in the require-dev section ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically legit, but no one is supposed to use dev-master now so it's not a real issue. This is mostly to make CI work with lowest dependencies as well (too bad there is no conflict-dev section).

Copy link

Choose a reason for hiding this comment

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

It doesn't make any sense to have a conflict-dev, as if you install the dev dependencies, it means you cloned the doctrine repo and working directly on it (you can't install dev dependencies of a dependency...). So making it into the dev section of the requirement and removing the conflict makes sense IMO.

Copy link
Member

Choose a reason for hiding this comment

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

So instead of how requiring it in the require-dev section ?

Nope, let's please not do that.

Users will be perfectly fine as long as they upgrade all their dependencies as they should be doing

Copy link
Member

@ostrolucky ostrolucky left a comment

Choose a reason for hiding this comment

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

Be careful about $hydrationMode, it can be a string for custom hydrators, see here. Yes, int in docblock was wrong all the time.

I've not highlighted all references, it became too much and would just clutter this PR

* @return mixed
*/
private function executeIgnoreQueryCache($parameters = null, $hydrationMode = null)
private function executeIgnoreQueryCache(?iterable $parameters = null, ?int $hydrationMode = null)
Copy link
Member

Choose a reason for hiding this comment

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

$hydrationMode can be string for custom hydrators

* @return mixed
*/
public function getResult($hydrationMode = self::HYDRATE_OBJECT)
public function getResult(int $hydrationMode = self::HYDRATE_OBJECT)
Copy link
Member

Choose a reason for hiding this comment

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

$hydrationMode can be string for custom hydrators

* @return mixed
*/
public function execute($parameters = null, $hydrationMode = null)
public function execute(?iterable $parameters = null, ?int $hydrationMode = null)
Copy link
Member

Choose a reason for hiding this comment

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

$hydrationMode can be string for custom hydrators

* @return mixed
*/
private function executeUsingQueryCache($parameters = null, $hydrationMode = null)
private function executeUsingQueryCache(?iterable $parameters = null, ?int $hydrationMode = null)
Copy link
Member

Choose a reason for hiding this comment

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

$hydrationMode can be string for custom hydrators

@Majkl578
Copy link
Contributor Author

@ostrolucky Thanks, adressed. Probably something to look into later to remove int|string union.

*
* @return object
*/
public function getEntity()
Copy link
Member

Choose a reason for hiding this comment

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

You removed return type annotation without adding return type. Same for following methods in this class

@Ocramius
Copy link
Member

Ocramius commented Apr 2, 2018

  • document signature changes - @Ocramius can you please suggest some format? Maybe outside UPGRADE to keep it clean, i.e. something like UPGRADE-STRICT-API.md with diff-like list of changes.

No idea how to make this clearer for readers. UPGRADE.md is the location read by people upgrading the lib: why would this be documented outside it?

@Ocramius
Copy link
Member

  • document signature changes - @Ocramius can you please suggest some format? Maybe outside UPGRADE to keep it clean, i.e. something like UPGRADE-STRICT-API.md with diff-like list of changes.

No idea how to make this clearer for readers. UPGRADE.md is the location read by people upgrading the lib: why would this be documented outside it?

Errata: I got a better idea here.

Let's try this upgrade path:

  1. all touched files must become either interface or final class - nothing in-between except for known edge-cases (EntityManager?)
  2. let's list all classes where final was added
  3. let's list all the interfaces in the diff

That's a sufficient UPGRADE.md entry.

@Ocramius
Copy link
Member

Also: I'm working on roave/api-compare this weekend: hope that will help in automating things. This patch is a good test-bed for that library too 👍 /cc @asgrim

@Majkl578 Majkl578 closed this Apr 16, 2019
@Majkl578 Majkl578 deleted the dev/strict-types branch April 16, 2019 19:51
@greg0ire greg0ire removed this from the 3.0.0 milestone Jun 27, 2021
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.

6 participants