-
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
Fix wrong types for AbstractQuery and child classes #9774
Fix wrong types for AbstractQuery and child classes #9774
Conversation
0bf0e20
to
4a12afa
Compare
* @return mixed[]|string|int|float|bool | ||
* @psalm-return array|scalar | ||
* @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.
I've seen DateTime
, CustomIdObject
and null
pass here when running unit tests with a native type declaration.
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.
That's basically mixed
, isn't it?
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.
Oh crap didn't see your answer… well I guess you can't have resource
in there but yeah, mixed might be better here 😅
lib/Doctrine/ORM/NativeQuery.php
Outdated
@@ -34,7 +34,7 @@ public function setSQL($sql): self | |||
/** | |||
* Gets the SQL query. | |||
* | |||
* @return mixed The built SQL query or an array of all SQL queries. | |||
* @return string The built SQL 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.
The class is final, and I don't see how we could have anything else than a string here.
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.
If you're sure about that, you can add a native return type. Doing that on a final
class is not a BC break.
@@ -1970,6 +1964,9 @@ | |||
<PropertyNotSetInConstructor occurrences="1"> | |||
<code>MultiTableUpdateExecutor</code> | |||
</PropertyNotSetInConstructor> | |||
<PropertyTypeCoercion occurrences="1"> | |||
<code>$this->_sqlStatements</code> | |||
</PropertyTypeCoercion> |
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.
The code is hard to analyse statically, but from my human point of view, what is intended here is a list
orm/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php
Lines 88 to 124 in 8f77012
$i = -1; | |
foreach (array_reverse($classNames) as $className) { | |
$affected = false; | |
$class = $em->getClassMetadata($className); | |
$updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class, $platform) . ' SET '; | |
foreach ($updateItems as $updateItem) { | |
$field = $updateItem->pathExpression->field; | |
if ( | |
(isset($class->fieldMappings[$field]) && ! isset($class->fieldMappings[$field]['inherited'])) || | |
(isset($class->associationMappings[$field]) && ! isset($class->associationMappings[$field]['inherited'])) | |
) { | |
$newValue = $updateItem->newValue; | |
if (! $affected) { | |
$affected = true; | |
++$i; | |
} else { | |
$updateSql .= ', '; | |
} | |
$updateSql .= $sqlWalker->walkUpdateItem($updateItem); | |
if ($newValue instanceof AST\InputParameter) { | |
$this->_sqlParameters[$i][] = $newValue->name; | |
++$this->_numParametersInUpdateClause; | |
} | |
} | |
} | |
if ($affected) { | |
$this->_sqlStatements[$i] = $updateSql . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')'; | |
} | |
} |
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.
Agree. mixed[]
doesn't fit for _sqlStatements.
4a12afa
to
920d278
Compare
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.
The issue references 3.0.0. Is 2.12.x
the expected target branch?
@@ -1970,6 +1964,9 @@ | |||
<PropertyNotSetInConstructor occurrences="1"> | |||
<code>MultiTableUpdateExecutor</code> | |||
</PropertyNotSetInConstructor> | |||
<PropertyTypeCoercion occurrences="1"> | |||
<code>$this->_sqlStatements</code> | |||
</PropertyTypeCoercion> |
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.
Agree. mixed[]
doesn't fit for _sqlStatements.
This PR is linked to 2 other PRs :) |
@@ -282,7 +283,7 @@ public function setCacheMode($cacheMode) | |||
* The returned SQL syntax depends on the connection driver that is used | |||
* by this query object at the time of this method call. | |||
* | |||
* @return string SQL query | |||
* @return list<string>|string SQL 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.
For 3.0, we should try to replace this method with one that always returns an array of strings.
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.
Doctrine noob here: I assume a single string is the SQL query, probably with placeholders and such, but what is an array of strings? And why would we prefer this for Doctrine 3?
@@ -596,7 +596,7 @@ public function free(): void | |||
/** | |||
* Sets a DQL query string. | |||
* | |||
* @param string $dqlQuery DQL Query. | |||
* @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.
This method is a no-op when null
is passed. Should we rather deprecate passing null
so that we can use string
as native parameter type in 3.0?
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 we rather deprecate passing null so that we can use string as native parameter type in 3.0?
Yes, but not rather. We should do so on 2.13.x.
I do not think we actually want to force our users to build an array collection when they want to use setParameters().
920d278
to
eb28264
Compare
eb28264
to
e9c868d
Compare
* 2.12.x: Fix wrong types for AbstractQuery and child classes (doctrine#9774) Document callable as possible Add use statement (doctrine#9769)
* 2.13.x: Make phpdoc more precise Deprecate setting fetch mode to random integers Prepare split of output walkers and tree walkers (doctrine#9786) PHPStan 1.7.0 (doctrine#9785) Deprecate passing null to Query::setDQL() Kill call_user_func(_array) (doctrine#9780) Fix wrong types for AbstractQuery and child classes (doctrine#9774) Document callable as possible Remove override phpdoc tag Add use statement (doctrine#9769)
Refs #9772