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

Explicitly allow to use Comparison and Composite in JOIN conditions #9022

Merged
merged 1 commit into from
Sep 20, 2021

Conversation

phansys
Copy link
Contributor

@phansys phansys commented Sep 18, 2021

These changes explicitly allow to use Comparison and Composite in JOIN conditions.
This is currently possible, but in an implicit way, since the values are silently converted to string as both classes are implementing the __toString() method.
After these changes, PHPStan findings like this, can be resolved:

Parameter #4 $condition of method Doctrine\ORM\QueryBuilder::join() expects string|null, Doctrine\ORM\Query\Expr\Andx given.

@phansys phansys force-pushed the join_condition branch 2 times, most recently from f5a2d43 to 436b65a Compare September 18, 2021 03:37
@phansys phansys marked this pull request as ready for review September 18, 2021 03:45
@greg0ire
Copy link
Member

Where does the conversion happen?
How do we know these classes are the only 2 possibilities?
I suppose you have considered using Stringable and rejected it?

@phansys
Copy link
Contributor Author

phansys commented Sep 19, 2021

Where does the conversion happen?

Join::__toString():

public function __toString()
{
return strtoupper($this->joinType) . ' JOIN ' . $this->join
. ($this->alias ? ' ' . $this->alias : '')
. ($this->indexBy ? ' INDEX BY ' . $this->indexBy : '')
. ($this->condition ? ' ' . strtoupper($this->conditionType) . ' ' . $this->condition : '');
}

How do we know these classes are the only 2 possibilities?

I don't know if there are more possibilities. These cases are what I have in my projects.
I guess we could add more cases if needed.

I suppose you have considered using Stringable and rejected it?

I considered this possibility, but as we might prefer to narrow the possibilities to classes we trust near its string representation, I decided to use them individually.

@@ -104,7 +104,7 @@ public function getConditionType()
}

/**
* @return string
* @return string|Comparison|Composite
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|Comparison|Composite
* @return string|Comparison|Composite|null

Seems like nullability is not documented correctly on any of the getters. Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that seems right IMO.
I didn't include this type because the same situation is present in other properties ($alias, $conditionType, $indexBy).
I think we should make a separate PR for these cases, as I suspect this is not the only class affected by this issue.
WDYT?

@phansys phansys requested a review from derrabus September 19, 2021 19:52
@derrabus derrabus merged commit 1f6401e into doctrine:2.9.x Sep 20, 2021
@phansys phansys deleted the join_condition branch September 20, 2021 04:18
derrabus added a commit to derrabus/orm that referenced this pull request Sep 29, 2021
* 2.9.x:
  Minor rewording (doctrine#8435)
  Don't presume one-to-one lookup returned an entity  (doctrine#9028)
  Minor change about double The (doctrine#9038)
  Remove duplicate comment (doctrine#9036)
  Fix docblock types for some nullable properties (doctrine#9024)
  Explicitly allow to use `Comparison` and `Composite` in JOIN conditions (doctrine#9022)
  Fix some typehints in QueryBuilder
  Bump PHPStan (doctrine#9014)
  Add tests for advanced types in collection matching
  Use types in collection persister

Signed-off-by: Alexander M. Turek <me@derrabus.de>
derrabus added a commit to derrabus/orm that referenced this pull request Sep 29, 2021
* 2.9.x:
  Minor rewording (doctrine#8435)
  Don't presume one-to-one lookup returned an entity  (doctrine#9028)
  Minor change about double The (doctrine#9038)
  Remove duplicate comment (doctrine#9036)
  Fix docblock types for some nullable properties (doctrine#9024)
  Explicitly allow to use `Comparison` and `Composite` in JOIN conditions (doctrine#9022)
  Fix some typehints in QueryBuilder
  Bump PHPStan (doctrine#9014)
  Add tests for advanced types in collection matching
  Use types in collection persister

Signed-off-by: Alexander M. Turek <me@derrabus.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants