-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
2ba2640
to
55c87e2
Compare
2a19761
to
a492e0a
Compare
@@ -217,59 +196,52 @@ public function setCacheRegion($cacheRegion) | |||
* | |||
* @return string|null The cache region name; NULL indicates the default region. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return string|null The cache region name; NULL indicates the default region. | |
* Returns the cache region name or NULL to indicate the default region. |
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/Doctrine/ORM/AbstractQuery.php
Outdated
* @return mixed[]|string|int|float|bool|object|null | ||
* @psalm-return array|scalar|object|null |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 👍
@derrabus I'm AFK until Sunday, feel free to push to my branch, I agree with all of your comments. |
174dd98
to
124073d
Compare
lib/Doctrine/ORM/Query.php
Outdated
@@ -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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
lib/Doctrine/ORM/Query.php
Outdated
* | ||
* @param string|null $dqlQuery DQL Query. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | |
* @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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
124073d
to
64ee704
Compare
64ee704
to
8399c8c
Compare
5d03a72
to
8e05c1c
Compare
); | ||
$fetchMode = Mapping\ClassMetadata::FETCH_LAZY; | ||
} | ||
|
There was a problem hiding this comment.
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 🤔
lib/Doctrine/ORM/AbstractQuery.php
Outdated
/** | ||
* The entity manager used by this query object. | ||
*/ | ||
protected EntityManagerInterface $_em |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/Doctrine/ORM/AbstractQuery.php
Outdated
|
||
$filteredParameters = $this->parameters->filter( | ||
static function (Query\Parameter $parameter) use ($key): bool { | ||
static function (Parameter $parameter) use ($key): bool { |
There was a problem hiding this comment.
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
);
8e05c1c
to
740ed9d
Compare
740ed9d
to
205d179
Compare
Both array and ArrayCollection are countable.
205d179
to
d462ed3
Compare
Blocked by
TODO: