Conversation
Implemented new methods in `WhereTrait` to support additional query conditions: `whereIsNull`, `whereIsNotNull`, and `whereIn`. Updated documentation and added comprehensive tests to validate functionality.
There was a problem hiding this comment.
Review by Korbit AI
Korbit automatically attempts to detect when you fix issues in new commits.
| Category | Issue | Status |
|---|---|---|
| Empty IN clause handling ▹ view | ||
| Restrictive Type for SQL Literals ▹ view | ✅ Fix detected | |
| Unsanitized field names in NULL checks ▹ view | ||
| Inefficient Unique Prefix Generation ▹ view | ✅ Fix detected |
Files scanned
| File Path | Reviewed |
|---|---|
| src/WhereTrait.php | ✅ |
| src/UpdateQuery.php | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
| public function whereIn(string $field, array $values): static | ||
| { | ||
| if (empty($values)) { | ||
| return $this; | ||
| } |
There was a problem hiding this comment.
Empty IN clause handling 
Tell me more
What is the issue?
The whereIn method silently returns without adding any condition when the values array is empty, which could lead to unexpected query results.
Why this matters
This behavior could inadvertently return all records instead of none when an empty array is provided, potentially exposing data that should be filtered out.
Suggested change ∙ Feature Preview
Modify the method to add a FALSE condition when values array is empty:
public function whereIn(string $field, array $values): static
{
if (empty($values)) {
$this->where[] = ['filter' => '1 = 0', 'params' => []];
return $this;
}Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| */ | ||
| public function whereIsNull(string $field): static | ||
| { | ||
| $this->where[] = ['filter' => "$field IS NULL", 'params' => []]; |
There was a problem hiding this comment.
Unsanitized field names in NULL checks 
Tell me more
What is the issue?
The whereIsNull and whereIsNotNull methods directly inject the field name into the SQL without any sanitization.
Why this matters
This could lead to SQL injection if the field parameter contains malicious SQL code, compromising database security.
Suggested change ∙ Feature Preview
Add field name validation or use a prepared statement approach:
private function validateFieldName(string $field): void
{
if (!preg_match('/^[a-zA-Z0-9_\.]+$/', $field)) {
throw new InvalidArgumentException('Invalid field name');
}
}
public function whereIsNull(string $field): static
{
$this->validateFieldName($field);
$this->where[] = ['filter' => "$field IS NULL", 'params' => []];
return $this;
}Provide feedback to improve future suggestions
💬 Looking for more details? Reply to this comment to chat with Korbit.
| // Generate a unique prefix for this whereIn call | ||
| $uniquePrefix = 'in_' . md5($field . microtime(true)) . '_'; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| * @param string $value | ||
| * @return $this | ||
| */ | ||
| public function setLiteral(string $field, string $value): UpdateQuery |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
…d optimized unique prefix generation for `whereIn`.
Added new query methods:
whereIsNull,whereIsNotNull, andwhereIn. These enhancements extend theWhereTraitfunctionality to handle null checks and inclusion queries. Documentation and tests have been updated to ensure accuracy and reliability.Description by Korbit AI
What change is being made?
Add new query methods
whereIsNull,whereIsNotNull, andwhereInfor handling IS NULL, IS NOT NULL, and IN conditions in SQL queries, and implement thesetLiteralmethod to support literal values inUpdateQuery.Why are these changes being made?
These changes enhance the library's functionality by providing native support for common SQL conditions, leading to more concise and readable query construction. The addition of the
setLiteralmethod allows users to directly embed database functions and expressions in updates, increasing flexibility when performing complex updates involving calculated fields or database functions.