Skip to content

Fix #730: Add ExpressionBuilderInterface::build() #946

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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

samdark
Copy link
Member

@samdark samdark commented Mar 27, 2025

Q A
Is bugfix?
New feature?
Breaks BC? ✔️
Fixed issues #730

TODO:

  • Decide on exception type that is thrown when type passed is incorrect.
  • Cover new lines with checks for argument type, with tests for exception being thrown.
  • Adjust method signature in driver packages.

@samdark samdark requested a review from Tigrov March 27, 2025 19:10
Copy link

codecov bot commented Mar 27, 2025

Codecov Report

Attention: Patch coverage is 72.34043% with 13 lines in your changes missing coverage. Please review.

Project coverage is 98.80%. Comparing base (adf6103) to head (0593fba).
Report is 19 commits behind head on master.

Files with missing lines Patch % Lines
src/Expression/AbstractArrayExpressionBuilder.php 50.00% 1 Missing ⚠️
src/Expression/AbstractExpressionBuilder.php 66.66% 1 Missing ⚠️
...Expression/AbstractStructuredExpressionBuilder.php 50.00% 1 Missing ⚠️
src/Expression/JsonExpressionBuilder.php 50.00% 1 Missing ⚠️
src/Query/QueryExpressionBuilder.php 66.66% 1 Missing ⚠️
...lder/Condition/Builder/BetweenConditionBuilder.php 75.00% 1 Missing ⚠️
.../Condition/Builder/ConjunctionConditionBuilder.php 75.00% 1 Missing ⚠️
...ilder/Condition/Builder/ExistsConditionBuilder.php 75.00% 1 Missing ⚠️
...Builder/Condition/Builder/HashConditionBuilder.php 75.00% 1 Missing ⚠️
...ryBuilder/Condition/Builder/InConditionBuilder.php 66.66% 1 Missing ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #946      +/-   ##
============================================
- Coverage     99.23%   98.80%   -0.44%     
- Complexity     1534     1548      +14     
============================================
  Files            98       98              
  Lines          3815     3843      +28     
============================================
+ Hits           3786     3797      +11     
- Misses           29       46      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samdark samdark marked this pull request as draft March 27, 2025 21:06
* @param array $params The binding parameters.
*
* @return string The raw SQL that won't be additionally escaped or quoted.
*/
public function build(ExpressionInterface $expression, array &$params = []): string
{
if (!$expression instanceof ArrayExpression) {
throw new InvalidArgumentException(static::class . ' could only be used with ArrayExpression.');
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we throw InvalidArgumentException or InvalidConfigException here?

Copy link
Member

Choose a reason for hiding this comment

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

The type check seems redundant, the value is then passed to a strongly typed method buildValue() where the right type specified.

@@ -68,13 +69,17 @@ public function __construct(protected readonly QueryBuilderInterface $queryBuild
/**
* The Method builds the raw SQL from the `$expression` that won't be additionally escaped or quoted.
*
* @param ArrayExpression $expression The expression to build.
* @param ExpressionInterface $expression The expression to build.
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 leave ArrayExpression here since it is the only valid type for the class method.

* @param array $params The binding parameters.
*
* @return string The raw SQL that won't be additionally escaped or quoted.
*/
public function build(ExpressionInterface $expression, array &$params = []): string
{
if (!$expression instanceof ArrayExpression) {
throw new InvalidArgumentException(static::class . ' could only be used with ArrayExpression.');
Copy link
Member

Choose a reason for hiding this comment

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

The type check seems redundant, the value is then passed to a strongly typed method buildValue() where the right type specified.

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