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

Migrate to PHP 8: AbstractQuery and child classes #9776

Merged
merged 5 commits into from Jun 3, 2022

Conversation

greg0ire
Copy link
Member

@greg0ire greg0ire commented May 22, 2022

Blocked by

TODO:

  • merge the above
  • merge up the patch branch
  • merge up the minor branch
  • run rector

@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 2ba2640 to 55c87e2 Compare May 22, 2022 14:53
lib/Doctrine/ORM/AbstractQuery.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/AbstractQuery.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/AbstractQuery.php Outdated Show resolved Hide resolved
@greg0ire greg0ire force-pushed the native-types-abstract-query branch 4 times, most recently from 2a19761 to a492e0a Compare May 25, 2022 06:46
@greg0ire greg0ire marked this pull request as ready for review May 25, 2022 06:48
lib/Doctrine/ORM/AbstractQuery.php Show resolved Hide resolved
@@ -217,59 +196,52 @@ public function setCacheRegion($cacheRegion)
*
* @return string|null The cache region name; NULL indicates the default region.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return string|null The cache region name; NULL indicates the default region.
* Returns the cache region name or NULL to indicate the default region.

lib/Doctrine/ORM/AbstractQuery.php Outdated Show resolved Hide resolved
@@ -348,7 +315,7 @@ static function (Query\Parameter $parameter) use ($key): bool {
*
* @return $this
*/
public function setParameters($parameters)
public function setParameters(ArrayCollection|array $parameters): static
Copy link
Member

Choose a reason for hiding this comment

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

We should try to narrow this down in 2.13.

Copy link
Member Author

Choose a reason for hiding this comment

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

🤔 what do you mean? Drop the ArrayCollection| part? I know I have never used it that way.

Comment on lines 365 to 361
* @return mixed[]|string|int|float|bool|object|null
* @psalm-return array|scalar|object|null
Copy link
Member

Choose a reason for hiding this comment

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

Do these annotations provide any real value? They're hardly more specifiy than mixed.

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'll try widening to mixed on 2.13.x, see if that impacts static analysis.

Copy link
Member Author

Choose a reason for hiding this comment

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

lib/Doctrine/ORM/AbstractQuery.php Outdated Show resolved Hide resolved
lib/Doctrine/ORM/AbstractQuery.php Outdated Show resolved Hide resolved
@@ -949,14 +870,12 @@ public function getHints()
* Executes the query and returns an iterable that can be used to incrementally
* iterate over the result.
*
* @param ArrayCollection|array|mixed[] $parameters The query parameters.
* @param string|int|null $hydrationMode The hydration mode to use.
* @psalm-param ArrayCollection<int, Parameter>|mixed[] $parameters
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit odd that we use iterable as native type, but a more specific ArrayCollection as annotated type. I think, we should fix the annotation.

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 agree it's a problem, but I don't think fixing the annotation is the right thing to do: down the line, we call setParameters, which can deal with mixed[], but not with ArrayCollection<stdClass>. It needs to be ArrayCollection<Parameter>.

Copy link
Member

Choose a reason for hiding this comment

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

You're right. But then, we should have the same native parameter type as setParameters(), so iterable should be ArrayCollection|array.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, definitely, I can change that in this PR 👍

@greg0ire
Copy link
Member Author

@derrabus I'm AFK until Sunday, feel free to push to my branch, I agree with all of your comments.

@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 174dd98 to 124073d Compare May 31, 2022 11:55
SenseException
SenseException previously approved these changes May 31, 2022
@@ -479,16 +451,12 @@ public function useQueryCache($bool): self
/**
* Defines how long the query cache will be active before expire.
*
* @param int $timeToLive How long the cache entry is valid.
* @param int|null $timeToLive How long the cache entry is valid.
Copy link
Member

Choose a reason for hiding this comment

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

Should be fixed on 2.13.x as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

"fixed"? 2.12.x then.

@@ -509,7 +477,7 @@ public function getQueryCacheLifetime(): ?int
*
* @return $this
*/
public function expireQueryCache($expire = true): self
public function expireQueryCache(bool $expire = true): self
Copy link
Member

Choose a reason for hiding this comment

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

We can delete the corresponding @param, I think.

Comment on lines 505 to 506
*
* @param string|null $dqlQuery 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.

Suggested change
*
* @param string|null $dqlQuery DQL Query.

@@ -597,7 +565,7 @@ public function contains($dql): bool
*
* @return $this
*/
public function setFirstResult($firstResult): self
public function setFirstResult(?int $firstResult): self
Copy link
Member

Choose a reason for hiding this comment

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

Shall we disallow null, to be consistent with the DBAL?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that would make sense. That will need to be initiated on 2.13.x

This was referenced Jun 1, 2022
@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 124073d to 64ee704 Compare June 1, 2022 21:07
@greg0ire greg0ire requested a review from derrabus June 1, 2022 21:15
@greg0ire greg0ire added this to In progress in PHP 8 Migration Jun 2, 2022
@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 64ee704 to 8399c8c Compare June 2, 2022 20:56
@greg0ire greg0ire marked this pull request as draft June 2, 2022 20:57
@greg0ire greg0ire changed the title Add native types to AbstractQuery Migrate to PHP 8: AbstractQuery and child classes Jun 2, 2022
@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 5d03a72 to 8e05c1c Compare June 2, 2022 21:22
);
$fetchMode = Mapping\ClassMetadata::FETCH_LAZY;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

From #9777 (comment) :

On 3.0, we would throw if the caller passed anything but the two allowed values, right?

Do we really want to do this? If yes, maybe we should require an assertion library 🤔

/**
* The entity manager used by this query object.
*/
protected EntityManagerInterface $_em
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather rename the property to em than adding that _ prefix to the constructor parameter, tbh.

Copy link
Member Author

Choose a reason for hiding this comment

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

Me too, that was me not questioning Rector's work.


$filteredParameters = $this->parameters->filter(
static function (Query\Parameter $parameter) use ($key): bool {
static function (Parameter $parameter) use ($key): bool {
Copy link
Member

Choose a reason for hiding this comment

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

$filteredParameters = $this->parameters->filter(
    static fn (Parameter $parameter): bool => $parameter->getName() === $key
);

@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 8e05c1c to 740ed9d Compare June 3, 2022 18:03
@greg0ire greg0ire marked this pull request as ready for review June 3, 2022 18:03
@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 740ed9d to 205d179 Compare June 3, 2022 18:06
derrabus
derrabus previously approved these changes Jun 3, 2022
@greg0ire greg0ire force-pushed the native-types-abstract-query branch from 205d179 to d462ed3 Compare June 3, 2022 18:51
@greg0ire greg0ire merged commit 53661fe into doctrine:3.0.x Jun 3, 2022
PHP 8 Migration automation moved this from In progress to Done Jun 3, 2022
@greg0ire greg0ire deleted the native-types-abstract-query branch June 3, 2022 18:53
@greg0ire greg0ire added this to the 3.0.0 milestone Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants