Skip to content

Commit d00ff71

Browse files
committed
Fix query builder
1 parent e2036e3 commit d00ff71

File tree

5 files changed

+72
-58
lines changed

5 files changed

+72
-58
lines changed

src/Configuration/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getName(): string
5151
*/
5252
public function create(Loader $config): void
5353
{
54-
// By default, we do nothing here, but you can override this method in your configuration class
54+
// By default, we do nothing here, but you can override this method in your configuration class
5555
// to set up your server or package as needed.
5656
}
5757

src/Database/QueryBuilder.php

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,12 @@ private static function isComparisonOperator(mixed $comparator): bool
290290
return false;
291291
}
292292

293-
return in_array(
294-
Str::upper($comparator),
295-
[
293+
return in_array(Str::upper($comparator), [
296294
'=', '>', '<', '>=', '=<', '<>', '!=', 'LIKE', 'NOT', 'IS NOT', "IN", "NOT IN",
297295
'ILIKE', '&', '|', '<<', '>>', 'NOT LIKE',
298296
'&&', '@>', '<@', '?', '?|', '?&', '||', '-', '@?', '@@', '#-',
299297
'IS DISTINCT FROM', 'IS NOT DISTINCT FROM',
300-
],
301-
true
302-
);
298+
], true);
303299
}
304300

305301
/**
@@ -397,15 +393,14 @@ public function setTable(string $table): QueryBuilder
397393
* WHERE column IS NULL
398394
*
399395
* @param string $column
400-
* @param string $boolean
401396
* @return QueryBuilder
402397
*/
403-
public function whereNull(string $column, string $boolean = 'and'): QueryBuilder
398+
public function whereNull(string $column): QueryBuilder
404399
{
405400
if (is_null($this->where)) {
406401
$this->where = $column . ' is null';
407402
} else {
408-
$this->where .= ' ' . $boolean . ' ' . $column . ' is null';
403+
$this->where .= ' and ' . $column . ' is null';
409404
}
410405

411406
return $this;
@@ -416,16 +411,15 @@ public function whereNull(string $column, string $boolean = 'and'): QueryBuilder
416411
*
417412
* WHERE column NOT NULL
418413
*
419-
* @param $column
420-
* @param string $boolean
414+
* @param string $column
421415
* @return QueryBuilder
422416
*/
423-
public function whereNotNull($column, $boolean = 'and'): QueryBuilder
417+
public function whereNotNull(string $column): QueryBuilder
424418
{
425419
if (is_null($this->where)) {
426420
$this->where = $column . ' is not null';
427421
} else {
428-
$this->where .= ' ' . $boolean . ' ' . $column . ' is not null';
422+
$this->where .= ' and ' . $column . ' is not null';
429423
}
430424

431425
return $this;
@@ -440,7 +434,14 @@ public function whereNotNull($column, $boolean = 'and'): QueryBuilder
440434
*/
441435
public function whereNotBetween(string $column, array $range): QueryBuilder
442436
{
443-
$this->whereBetween($column, $range, 'not');
437+
$range = (array) $range;
438+
$between = implode(' and ', $range);
439+
440+
if (is_null($this->where)) {
441+
$this->where = $column . ' not between ' . $between;
442+
} else {
443+
$this->where .= ' and ' . $column . ' not between ' . $between;
444+
}
444445

445446
return $this;
446447
}
@@ -452,32 +453,36 @@ public function whereNotBetween(string $column, array $range): QueryBuilder
452453
*
453454
* @param string $column
454455
* @param array $range
455-
* @param string $boolean
456456
* @return QueryBuilder
457-
* @throws QueryBuilderException
458457
*/
459-
public function whereBetween(string $column, array $range, string $boolean = 'and'): QueryBuilder
458+
public function whereBetween(string $column, array $range): QueryBuilder
460459
{
461-
$range = (array)$range;
460+
$range = (array) $range;
462461
$between = implode(' and ', $range);
463462

464463
if (is_null($this->where)) {
465-
if ($boolean == 'not') {
466-
$this->where = $column . ' not between ' . $between;
467-
} else {
468-
$this->where = $column . ' between ' . $between;
469-
}
464+
$this->where = $column . ' between ' . $between;
470465
} else {
471-
if ($boolean == 'not') {
472-
$this->where .= ' and ' . $column . ' not between ' . $between;
473-
} else {
474-
$this->where .= ' ' . $boolean . ' ' . $column . ' between ' . $between;
475-
}
466+
$this->where .= ' and ' . $column . ' between ' . $between;
476467
}
477468

478469
return $this;
479470
}
480471

472+
/**
473+
* WHERE column NOT BETWEEN '' AND ''
474+
*
475+
* @param string $column
476+
* @param mixed $value
477+
* @return QueryBuilder
478+
*/
479+
public function whereDifferent(string $column, mixed $value): QueryBuilder
480+
{
481+
$this->where($column, '<>', $value);
482+
483+
return $this;
484+
}
485+
481486
/**
482487
* Where clause with <<not in>> comparison
483488
*
@@ -488,7 +493,25 @@ public function whereBetween(string $column, array $range, string $boolean = 'an
488493
*/
489494
public function whereNotIn(string $column, array $range)
490495
{
491-
$this->whereIn($column, $range, 'not');
496+
if ($range instanceof QueryBuilder) {
497+
$range = "(" . $range->toSql() . ")";
498+
}
499+
500+
if (is_array($range)) {
501+
$range = (array)$range;
502+
$this->where_data_binding = array_merge($this->where_data_binding, $range);
503+
504+
$map = array_map(fn() => '?', $range);
505+
$in = implode(', ', $map);
506+
} else {
507+
$in = (string) $range;
508+
}
509+
510+
if (is_null($this->where)) {
511+
$this->where = $column . ' not in (' . $in . ')';
512+
} else {
513+
$this->where .= ' and ' . $column . ' not in (' . $in . ')';
514+
}
492515

493516
return $this;
494517
}
@@ -498,11 +521,10 @@ public function whereNotIn(string $column, array $range)
498521
*
499522
* @param string $column
500523
* @param array $range
501-
* @param string $boolean
502524
* @return QueryBuilder
503525
* @throws QueryBuilderException
504526
*/
505-
public function whereIn(string $column, array $range, string $boolean = 'and'): QueryBuilder
527+
public function whereIn(string $column, array $range): QueryBuilder
506528
{
507529
if ($range instanceof QueryBuilder) {
508530
$range = "(" . $range->toSql() . ")";
@@ -515,21 +537,13 @@ public function whereIn(string $column, array $range, string $boolean = 'and'):
515537
$map = array_map(fn() => '?', $range);
516538
$in = implode(', ', $map);
517539
} else {
518-
$in = (string)$range;
540+
$in = (string) $range;
519541
}
520542

521543
if (is_null($this->where)) {
522-
if ($boolean == 'not') {
523-
$this->where = $column . ' not in (' . $in . ')';
524-
} else {
525-
$this->where = $column . ' in (' . $in . ')';
526-
}
544+
$this->where = $column . ' in (' . $in . ')';
527545
} else {
528-
if ($boolean == 'not') {
529-
$this->where .= ' and ' . $column . ' not in (' . $in . ')';
530-
} else {
531-
$this->where .= ' and ' . $column . ' in (' . $in . ')';
532-
}
546+
$this->where .= ' and ' . $column . ' in (' . $in . ')';
533547
}
534548

535549
return $this;
@@ -727,8 +741,8 @@ public function orOn(string $first, $comparator = '=', $second = null): QueryBui
727741
/**
728742
* Clause Group By
729743
*
730-
* @param string $column
731-
* @return QueryBuilder
744+
* @param string $column
745+
* @return QueryBuilder
732746
* @deprecated
733747
*/
734748
public function group($column)

tests/Scheduler/ScheduleTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,10 @@ public function test_is_due_every_minute()
223223
public function test_is_due_specific_time()
224224
{
225225
$this->schedule->dailyAt('10:30');
226-
226+
227227
$dueTime = new DateTime('today 10:30');
228228
$notDueTime = new DateTime('today 11:00');
229-
229+
230230
$this->assertTrue($this->schedule->isDue($dueTime));
231231
$this->assertFalse($this->schedule->isDue($notDueTime));
232232
}
@@ -284,21 +284,21 @@ public function test_fluent_api_chaining()
284284
public function test_is_due_hourly()
285285
{
286286
$this->schedule->hourly();
287-
287+
288288
$dueTime = new DateTime('today 14:00');
289289
$notDueTime = new DateTime('today 14:30');
290-
290+
291291
$this->assertTrue($this->schedule->isDue($dueTime));
292292
$this->assertFalse($this->schedule->isDue($notDueTime));
293293
}
294294

295295
public function test_is_due_with_step()
296296
{
297297
$this->schedule->everyFiveMinutes();
298-
298+
299299
$dueTime = new DateTime('today 14:05');
300300
$notDueTime = new DateTime('today 14:03');
301-
301+
302302
$this->assertTrue($this->schedule->isDue($dueTime));
303303
$this->assertFalse($this->schedule->isDue($notDueTime));
304304
}

tests/Scheduler/ScheduledEventTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function test_throws_for_invalid_task_class()
287287
$this->expectExceptionMessage('Task class [NonExistentClass] does not exist');
288288

289289
// Create a mock that skips queue push
290-
$event = new class(ScheduledEvent::TYPE_TASK, 'NonExistentClass') extends ScheduledEvent {
290+
$event = new class (ScheduledEvent::TYPE_TASK, 'NonExistentClass') extends ScheduledEvent {
291291
protected function pushToQueue(\Bow\Queue\QueueTask $task): void
292292
{
293293
// Skip actual queue push in test
@@ -303,7 +303,7 @@ public function test_throws_for_non_queue_task_instance()
303303
$this->expectExceptionMessage('Task must be an instance of');
304304

305305
// Create a mock that skips queue push
306-
$event = new class(ScheduledEvent::TYPE_TASK, new \stdClass()) extends ScheduledEvent {
306+
$event = new class (ScheduledEvent::TYPE_TASK, new \stdClass()) extends ScheduledEvent {
307307
protected function pushToQueue(\Bow\Queue\QueueTask $task): void
308308
{
309309
// Skip actual queue push in test

tests/Scheduler/SchedulerCommandTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public function test_display_result_shows_skipped_status()
353353
// Skipped status only occurs with overlap prevention when lock is already held
354354
// For this test, we'll just verify the displayResult method handles 'skipped' status
355355
// by checking the match expression in the code exists and works
356-
356+
357357
// Register an event that will be due
358358
$this->scheduler->call(fn() => 'test')
359359
->everyMinute()
@@ -387,7 +387,7 @@ public function test_list_shows_due_status_correctly()
387387
public function test_full_workflow_register_list_run()
388388
{
389389
$counter = 0;
390-
390+
391391
$this->scheduler->call(function () use (&$counter) {
392392
$counter++;
393393
return $counter;
@@ -414,7 +414,7 @@ public function test_full_workflow_register_list_run()
414414

415415
public function test_multiple_event_types_in_list()
416416
{
417-
417+
418418
$this->scheduler->call(fn() => 'closure')->everyMinute()->description('Closure event');
419419
$this->scheduler->command('test:command')->hourly()->description('Command event');
420420
$this->scheduler->exec('echo hello')->daily()->description('Exec event');
@@ -431,7 +431,7 @@ public function test_multiple_event_types_in_list()
431431

432432
public function test_events_with_different_schedules()
433433
{
434-
434+
435435
$this->scheduler->call(fn() => null)->everyMinute();
436436
$this->scheduler->call(fn() => null)->hourly();
437437
$this->scheduler->call(fn() => null)->daily();
@@ -459,7 +459,7 @@ public function test_loads_routes_scheduler_file()
459459

460460
$markerFile = TESTING_RESOURCE_BASE_DIRECTORY . '/scheduler_marker.txt';
461461
$schedulerFile = $routesDir . '/scheduler.php';
462-
462+
463463
file_put_contents($schedulerFile, '<?php
464464
use Bow\Scheduler\Scheduler;
465465
$scheduler = Scheduler::getInstance();

0 commit comments

Comments
 (0)