From c2197bb6c1b0cce748112b5d76fca82e85e05f63 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Mar 2022 17:48:19 +0700 Subject: [PATCH 01/14] (+) fix whereDate, whereMonth, whereYear, whereTime to use $expr and respective query rather than using basic comparison --- src/Query/Builder.php | 117 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 16 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index f83bce3e2..07fc51fba 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -7,6 +7,7 @@ use Illuminate\Database\Query\Builder as BaseBuilder; use Illuminate\Database\Query\Expression; use Illuminate\Support\Arr; +use Illuminate\Support\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\LazyCollection; use Illuminate\Support\Str; @@ -1163,10 +1164,40 @@ protected function compileWhereDate(array $where) { extract($where); - $where['operator'] = $operator; - $where['value'] = $value; + $date = Carbon::parse($value); - return $this->compileWhereBasic($where); + $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; + + return [ + '$expr' => [ + '$and' => [ + [ + $operator => [ + [ + '$dayOfMonth' => '$'.$column + ], + $date->day + ], + ], + [ + $operator => [ + [ + '$month' => '$'.$column + ], + $date->month + ], + ], + [ + $operator => [ + [ + '$month' => '$'.$column + ], + $date->year + ], + ], + ], + ], + ]; } /** @@ -1177,10 +1208,18 @@ protected function compileWhereMonth(array $where) { extract($where); - $where['operator'] = $operator; - $where['value'] = $value; + $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; - return $this->compileWhereBasic($where); + return [ + '$expr' => [ + $operator => [ + [ + '$month' => '$'.$column + ], + $value, + ], + ], + ]; } /** @@ -1191,10 +1230,18 @@ protected function compileWhereDay(array $where) { extract($where); - $where['operator'] = $operator; - $where['value'] = $value; + $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; - return $this->compileWhereBasic($where); + return [ + '$expr' => [ + $operator => [ + [ + '$dayOfMonth' => '$'.$column + ], + $value, + ], + ], + ]; } /** @@ -1204,11 +1251,19 @@ protected function compileWhereDay(array $where) protected function compileWhereYear(array $where) { extract($where); + + $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; - $where['operator'] = $operator; - $where['value'] = $value; - - return $this->compileWhereBasic($where); + return [ + '$expr' => [ + $operator => [ + [ + '$year' => '$'.$column + ], + $value + ], + ], + ]; } /** @@ -1219,10 +1274,40 @@ protected function compileWhereTime(array $where) { extract($where); - $where['operator'] = $operator; - $where['value'] = $value; + $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; - return $this->compileWhereBasic($where); + $time = Carbon::parse($value); + + return [ + '$expr' => [ + '$and' => [ + [ + $operator => [ + [ + '$hour' => '$'.$column + ], + $time->hour + ], + ], + [ + $operator => [ + [ + '$minute' => '$'.$column + ], + $time->minute + ], + ], + [ + $operator => [ + [ + '$second' => '$'.$column + ], + $time->second + ], + ], + ], + ], + ]; } /** From 85de6d7d093c33e02b90baff76ef46bec1936164 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Mar 2022 17:48:26 +0700 Subject: [PATCH 02/14] (+) fix testing --- tests/QueryTest.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/QueryTest.php b/tests/QueryTest.php index b2716e178..e8e1bdcf0 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -2,6 +2,8 @@ declare(strict_types=1); +use Carbon\Carbon; + class QueryTest extends TestCase { protected static $started = false; @@ -18,12 +20,12 @@ public function setUp(): void User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']); User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']); User::create(['name' => 'Error', 'age' => null, 'title' => null]); - Birthday::create(['name' => 'Mark Moe', 'birthday' => '2020-04-10', 'day' => '10', 'month' => '04', 'year' => '2020', 'time' => '10:53:11']); - Birthday::create(['name' => 'Jane Doe', 'birthday' => '2021-05-12', 'day' => '12', 'month' => '05', 'year' => '2021', 'time' => '10:53:12']); - Birthday::create(['name' => 'Harry Hoe', 'birthday' => '2021-05-11', 'day' => '11', 'month' => '05', 'year' => '2021', 'time' => '10:53:13']); - Birthday::create(['name' => 'Robert Doe', 'birthday' => '2021-05-12', 'day' => '12', 'month' => '05', 'year' => '2021', 'time' => '10:53:14']); - Birthday::create(['name' => 'Mark Moe', 'birthday' => '2021-05-12', 'day' => '12', 'month' => '05', 'year' => '2021', 'time' => '10:53:15']); - Birthday::create(['name' => 'Mark Moe', 'birthday' => '2022-05-12', 'day' => '12', 'month' => '05', 'year' => '2022', 'time' => '10:53:16']); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString()); + Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString()); + Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString()); + Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString()); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString()); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString()); } public function tearDown(): void @@ -181,40 +183,40 @@ public function testWhereDate(): void public function testWhereDay(): void { - $day = Birthday::whereDay('day', '12')->get(); + $day = Birthday::whereDay('birthday', 12)->get(); $this->assertCount(4, $day); - $day = Birthday::whereDay('day', '11')->get(); + $day = Birthday::whereDay('birthday', 11)->get(); $this->assertCount(1, $day); } public function testWhereMonth(): void { - $month = Birthday::whereMonth('month', '04')->get(); + $month = Birthday::whereMonth('birthday', 4)->get(); $this->assertCount(1, $month); - $month = Birthday::whereMonth('month', '05')->get(); + $month = Birthday::whereMonth('birthday', 5)->get(); $this->assertCount(5, $month); } public function testWhereYear(): void { - $year = Birthday::whereYear('year', '2021')->get(); + $year = Birthday::whereYear('birthday', 2021)->get(); $this->assertCount(4, $year); - $year = Birthday::whereYear('year', '2022')->get(); + $year = Birthday::whereYear('birthday', 2022)->get(); $this->assertCount(1, $year); - $year = Birthday::whereYear('year', '<', '2021')->get(); + $year = Birthday::whereYear('birthday', '<', 2021)->get(); $this->assertCount(1, $year); } public function testWhereTime(): void { - $time = Birthday::whereTime('time', '10:53:11')->get(); + $time = Birthday::whereTime('birthday', '10:53:11')->get(); $this->assertCount(1, $time); - $time = Birthday::whereTime('time', '>=', '10:53:14')->get(); + $time = Birthday::whereTime('birthday', '>=', '10:53:14')->get(); $this->assertCount(3, $time); } From 9e8a63ebc734bbad4586d389142d79d8429eca0e Mon Sep 17 00:00:00 2001 From: David Date: Sun, 27 Mar 2022 18:13:08 +0700 Subject: [PATCH 03/14] (+) remove unused property --- tests/models/Birthday.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/models/Birthday.php b/tests/models/Birthday.php index 3e725e495..0e9930240 100644 --- a/tests/models/Birthday.php +++ b/tests/models/Birthday.php @@ -9,14 +9,10 @@ * * @property string $name * @property string $birthday - * @property string $day - * @property string $month - * @property string $year - * @property string $time */ class Birthday extends Eloquent { protected $connection = 'mongodb'; protected $collection = 'birthday'; - protected $fillable = ['name', 'birthday', 'day', 'month', 'year', 'time']; + protected $fillable = ['name', 'birthday']; } From f942ad810e06e91833515877ada451a6de32fd58 Mon Sep 17 00:00:00 2001 From: David Surya Date: Sun, 27 Mar 2022 21:25:30 +0700 Subject: [PATCH 04/14] (+) fix whereDay and whereMonth --- src/Query/Builder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 07fc51fba..47bbd9242 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -1231,6 +1231,7 @@ protected function compileWhereDay(array $where) extract($where); $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; + $value = str_starts_with($value, '0') ? intval(str_replace('0', '', $value)) : $value; return [ '$expr' => [ @@ -1253,6 +1254,7 @@ protected function compileWhereYear(array $where) extract($where); $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; + $value = str_starts_with($value, '0') ? intval(str_replace('0', '', $value)) : $value; return [ '$expr' => [ From d37cdf688df49380b3da44bef28f45fd5f37c9bd Mon Sep 17 00:00:00 2001 From: David Surya Date: Sun, 27 Mar 2022 21:28:16 +0700 Subject: [PATCH 05/14] (+) move value conversion from whereYear to whereMonth --- src/Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 47bbd9242..db413b7a2 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -1209,6 +1209,7 @@ protected function compileWhereMonth(array $where) extract($where); $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; + $value = str_starts_with($value, '0') ? intval(str_replace('0', '', $value)) : $value; return [ '$expr' => [ @@ -1254,7 +1255,6 @@ protected function compileWhereYear(array $where) extract($where); $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; - $value = str_starts_with($value, '0') ? intval(str_replace('0', '', $value)) : $value; return [ '$expr' => [ From e2c30233925f5a1c0549e4e5758eea4c6ba0b4ab Mon Sep 17 00:00:00 2001 From: David Surya Date: Sun, 27 Mar 2022 21:39:23 +0700 Subject: [PATCH 06/14] (+) fix whereDate operator for day (+) fix whereDate operator for month and year --- src/Query/Builder.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index db413b7a2..7f5cf8f4c 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -1166,13 +1166,15 @@ protected function compileWhereDate(array $where) $date = Carbon::parse($value); - $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; + $operator = $this->conversion[$operator]; + $operatorDay = $operator === '=' ? '$eq' : $operator; + $operatorMonthYear = $operator === '=' ? '$eq' : (in_array($operator, ['$gt', '$lt']) ? $operator . 'e' : $operator); return [ '$expr' => [ '$and' => [ [ - $operator => [ + $operatorDay => [ [ '$dayOfMonth' => '$'.$column ], @@ -1180,7 +1182,7 @@ protected function compileWhereDate(array $where) ], ], [ - $operator => [ + $operatorMonthYear => [ [ '$month' => '$'.$column ], @@ -1188,9 +1190,9 @@ protected function compileWhereDate(array $where) ], ], [ - $operator => [ + $operatorMonthYear => [ [ - '$month' => '$'.$column + '$year' => '$'.$column ], $date->year ], From 078c607a741e6e27f67c5f7f9570a72cfe64dfa9 Mon Sep 17 00:00:00 2001 From: David Surya Date: Mon, 28 Mar 2022 19:40:19 +0700 Subject: [PATCH 07/14] (+) use new logic for whereDate --- src/Query/Builder.php | 65 ++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 7f5cf8f4c..f378b1f6b 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -1164,42 +1164,45 @@ protected function compileWhereDate(array $where) { extract($where); - $date = Carbon::parse($value); + $startOfDay = new UTCDateTime(Carbon::parse($value)->startOfDay()); + $endOfDay = new UTCDateTime(Carbon::parse($value)->endOfDay()); $operator = $this->conversion[$operator]; - $operatorDay = $operator === '=' ? '$eq' : $operator; - $operatorMonthYear = $operator === '=' ? '$eq' : (in_array($operator, ['$gt', '$lt']) ? $operator . 'e' : $operator); - return [ - '$expr' => [ - '$and' => [ - [ - $operatorDay => [ - [ - '$dayOfMonth' => '$'.$column - ], - $date->day - ], - ], - [ - $operatorMonthYear => [ - [ - '$month' => '$'.$column - ], - $date->month - ], - ], - [ - $operatorMonthYear => [ - [ - '$year' => '$'.$column - ], - $date->year - ], - ], + return match($operator) { + '=' => [ + $column => [ + '$gte' => $startOfDay, + '$lte' => $endOfDay, ], ], - ]; + '$ne' => [ + $column => [ + '$gt' => $endOfDay, + '$lt' => $startOfDay, + ], + ], + '$lt' => [ + $column => [ + '$lt' => $startOfDay, + ], + ], + '$gt' => [ + $column => [ + '$gt' => $endOfDay, + ], + ], + '$lte' => [ + $column => [ + '$lte' => $endOfDay, + ], + ], + '$gte' => [ + $column => [ + '$gte' => $startOfDay, + ], + ], + }; } /** From 800c89142208c33fc44323e485d719daeb80fca8 Mon Sep 17 00:00:00 2001 From: David Surya Date: Mon, 28 Mar 2022 19:46:55 +0700 Subject: [PATCH 08/14] (+) rollback whereTime since its not possible to begin with on mongodb --- src/Query/Builder.php | 36 +++--------------------------------- tests/QueryTest.php | 16 ++++++++-------- tests/models/Birthday.php | 3 ++- 3 files changed, 13 insertions(+), 42 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index f378b1f6b..f979d707d 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -1281,40 +1281,10 @@ protected function compileWhereTime(array $where) { extract($where); - $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; - - $time = Carbon::parse($value); + $where['operator'] = $operator; + $where['value'] = $value; - return [ - '$expr' => [ - '$and' => [ - [ - $operator => [ - [ - '$hour' => '$'.$column - ], - $time->hour - ], - ], - [ - $operator => [ - [ - '$minute' => '$'.$column - ], - $time->minute - ], - ], - [ - $operator => [ - [ - '$second' => '$'.$column - ], - $time->second - ], - ], - ], - ], - ]; + return $this->compileWhereBasic($where); } /** diff --git a/tests/QueryTest.php b/tests/QueryTest.php index e8e1bdcf0..c1cde2c6d 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -20,12 +20,12 @@ public function setUp(): void User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']); User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']); User::create(['name' => 'Error', 'age' => null, 'title' => null]); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString()); - Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString()); - Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString()); - Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString()); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString()); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString()); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString(), 'time' => '10:53:11'); + Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString(), 'time' => '10:53:12'); + Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString(), 'time' => '10:53:13'); + Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString(), 'time' => '10:53:14'); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString(), 'time' => '10:53:15'); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString(), 'time' => '10:53:16'); } public function tearDown(): void @@ -213,10 +213,10 @@ public function testWhereYear(): void public function testWhereTime(): void { - $time = Birthday::whereTime('birthday', '10:53:11')->get(); + $time = Birthday::whereTime('time', '10:53:11')->get(); $this->assertCount(1, $time); - $time = Birthday::whereTime('birthday', '>=', '10:53:14')->get(); + $time = Birthday::whereTime('time', '>=', '10:53:14')->get(); $this->assertCount(3, $time); } diff --git a/tests/models/Birthday.php b/tests/models/Birthday.php index 0e9930240..ddb776d4c 100644 --- a/tests/models/Birthday.php +++ b/tests/models/Birthday.php @@ -9,10 +9,11 @@ * * @property string $name * @property string $birthday + * @property string $time */ class Birthday extends Eloquent { protected $connection = 'mongodb'; protected $collection = 'birthday'; - protected $fillable = ['name', 'birthday']; + protected $fillable = ['name', 'birthday', 'time']; } From c02bca597ebe7001a81caab49692bc3691fa531d Mon Sep 17 00:00:00 2001 From: David Surya Date: Mon, 28 Mar 2022 20:10:36 +0700 Subject: [PATCH 09/14] (+) fix styleci --- src/Query/Builder.php | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index f979d707d..21a080c77 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -141,7 +141,7 @@ public function __construct(Connection $connection, Processor $processor) /** * Set the projections. * - * @param array $columns + * @param array $columns * @return $this */ public function project($columns) @@ -153,7 +153,7 @@ public function project($columns) /** * Set the cursor timeout in seconds. - * @param int $seconds + * @param int $seconds * @return $this */ public function timeout($seconds) @@ -166,7 +166,7 @@ public function timeout($seconds) /** * Set the cursor hint. * - * @param mixed $index + * @param mixed $index * @return $this */ public function hint($index) @@ -217,8 +217,8 @@ public function cursor($columns = []) /** * Execute the query as a fresh "select" statement. * - * @param array $columns - * @param bool $returnLazy + * @param array $columns + * @param bool $returnLazy * @return array|static[]|Collection|LazyCollection */ public function getFresh($columns = [], $returnLazy = false) @@ -522,10 +522,10 @@ public function orderBy($column, $direction = 'asc') /** * Add a "where all" clause to the query. * - * @param string $column - * @param array $values - * @param string $boolean - * @param bool $not + * @param string $column + * @param array $values + * @param string $boolean + * @param bool $not * @return $this */ public function whereAll($column, array $values, $boolean = 'and', $not = false) @@ -729,8 +729,8 @@ public function truncate(): bool /** * Get an array with the values of a given column. * - * @param string $column - * @param string $key + * @param string $column + * @param string $key * @return array * @deprecated */ @@ -761,9 +761,9 @@ public function raw($expression = null) /** * Append one or more values to an array. * - * @param mixed $column - * @param mixed $value - * @param bool $unique + * @param mixed $column + * @param mixed $value + * @param bool $unique * @return int */ public function push($column, $value = null, $unique = false) @@ -788,8 +788,8 @@ public function push($column, $value = null, $unique = false) /** * Remove one or more values from an array. * - * @param mixed $column - * @param mixed $value + * @param mixed $column + * @param mixed $value * @return int */ public function pull($column, $value = null) @@ -812,7 +812,7 @@ public function pull($column, $value = null) /** * Remove one or more fields. * - * @param mixed $columns + * @param mixed $columns * @return int */ public function drop($columns) @@ -843,8 +843,8 @@ public function newQuery() /** * Perform an update query. * - * @param array $query - * @param array $options + * @param array $query + * @param array $options * @return int */ protected function performUpdate($query, array $options = []) @@ -866,7 +866,7 @@ protected function performUpdate($query, array $options = []) /** * Convert a key to ObjectID if needed. * - * @param mixed $id + * @param mixed $id * @return mixed */ public function convertKey($id) @@ -1000,7 +1000,7 @@ protected function compileWheres() } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereAll(array $where) @@ -1011,7 +1011,7 @@ protected function compileWhereAll(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereBasic(array $where) @@ -1067,7 +1067,7 @@ protected function compileWhereBasic(array $where) } /** - * @param array $where + * @param array $where * @return mixed */ protected function compileWhereNested(array $where) @@ -1078,7 +1078,7 @@ protected function compileWhereNested(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereIn(array $where) @@ -1089,7 +1089,7 @@ protected function compileWhereIn(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereNotIn(array $where) @@ -1100,7 +1100,7 @@ protected function compileWhereNotIn(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereNull(array $where) @@ -1112,7 +1112,7 @@ protected function compileWhereNull(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereNotNull(array $where) @@ -1124,7 +1124,7 @@ protected function compileWhereNotNull(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereBetween(array $where) @@ -1157,7 +1157,7 @@ protected function compileWhereBetween(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereDate(array $where) @@ -1169,7 +1169,7 @@ protected function compileWhereDate(array $where) $operator = $this->conversion[$operator]; - return match($operator) { + return match ($operator) { '=' => [ $column => [ '$gte' => $startOfDay, @@ -1206,7 +1206,7 @@ protected function compileWhereDate(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereMonth(array $where) @@ -1220,7 +1220,7 @@ protected function compileWhereMonth(array $where) '$expr' => [ $operator => [ [ - '$month' => '$'.$column + '$month' => '$'.$column, ], $value, ], @@ -1229,7 +1229,7 @@ protected function compileWhereMonth(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereDay(array $where) @@ -1243,7 +1243,7 @@ protected function compileWhereDay(array $where) '$expr' => [ $operator => [ [ - '$dayOfMonth' => '$'.$column + '$dayOfMonth' => '$'.$column, ], $value, ], @@ -1252,7 +1252,7 @@ protected function compileWhereDay(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereYear(array $where) @@ -1265,16 +1265,16 @@ protected function compileWhereYear(array $where) '$expr' => [ $operator => [ [ - '$year' => '$'.$column + '$year' => '$'.$column, ], - $value + $value, ], ], ]; } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereTime(array $where) @@ -1288,7 +1288,7 @@ protected function compileWhereTime(array $where) } /** - * @param array $where + * @param array $where * @return mixed */ protected function compileWhereRaw(array $where) @@ -1299,7 +1299,7 @@ protected function compileWhereRaw(array $where) /** * Set custom options for the query. * - * @param array $options + * @param array $options * @return $this */ public function options(array $options) From 3801ac7754551e564adc2892ed69ce71fb84394d Mon Sep 17 00:00:00 2001 From: David Surya Date: Mon, 28 Mar 2022 20:11:37 +0700 Subject: [PATCH 10/14] (+) fix tests --- tests/QueryTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/QueryTest.php b/tests/QueryTest.php index c1cde2c6d..b8b4eb23e 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -20,12 +20,12 @@ public function setUp(): void User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']); User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']); User::create(['name' => 'Error', 'age' => null, 'title' => null]); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString(), 'time' => '10:53:11'); - Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString(), 'time' => '10:53:12'); - Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString(), 'time' => '10:53:13'); - Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString(), 'time' => '10:53:14'); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString(), 'time' => '10:53:15'); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString(), 'time' => '10:53:16'); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString(), 'time' => '10:53:11']); + Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString(), 'time' => '10:53:12']); + Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString(), 'time' => '10:53:13']); + Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString(), 'time' => '10:53:14']); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString(), 'time' => '10:53:15']); + Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString(), 'time' => '10:53:16']); } public function tearDown(): void From 0fa6784333772ff463ee386174d4c67c1fca7063 Mon Sep 17 00:00:00 2001 From: David Surya Date: Mon, 28 Mar 2022 20:12:38 +0700 Subject: [PATCH 11/14] (+) fix styleci --- src/Query/Builder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index 21a080c77..f7f70adff 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -153,6 +153,7 @@ public function project($columns) /** * Set the cursor timeout in seconds. + * * @param int $seconds * @return $this */ @@ -732,6 +733,7 @@ public function truncate(): bool * @param string $column * @param string $key * @return array + * * @deprecated */ public function lists($column, $key = null) @@ -1252,7 +1254,7 @@ protected function compileWhereDay(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereYear(array $where) From 08db883a4e8fc5cf871acaa80f52cd5e9a2025eb Mon Sep 17 00:00:00 2001 From: David Surya Date: Mon, 28 Mar 2022 20:13:33 +0700 Subject: [PATCH 12/14] (+) fix styleci --- src/Query/Builder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index f7f70adff..da48e3701 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -153,7 +153,7 @@ public function project($columns) /** * Set the cursor timeout in seconds. - * + * * @param int $seconds * @return $this */ @@ -733,7 +733,7 @@ public function truncate(): bool * @param string $column * @param string $key * @return array - * + * * @deprecated */ public function lists($column, $key = null) @@ -1260,7 +1260,7 @@ protected function compileWhereDay(array $where) protected function compileWhereYear(array $where) { extract($where); - + $operator = $operator === '=' ? '$eq' : $this->conversion[$operator]; return [ From e0f6b6dc0935b7345752391d17fb67681f3e69f5 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 18 Jan 2023 16:21:26 +0700 Subject: [PATCH 13/14] Revert "(+) fix styleci" This reverts commit c02bca597ebe7001a81caab49692bc3691fa531d. --- src/Query/Builder.php | 81 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/src/Query/Builder.php b/src/Query/Builder.php index da48e3701..30e6297cb 100644 --- a/src/Query/Builder.php +++ b/src/Query/Builder.php @@ -141,7 +141,7 @@ public function __construct(Connection $connection, Processor $processor) /** * Set the projections. * - * @param array $columns + * @param array $columns * @return $this */ public function project($columns) @@ -153,8 +153,7 @@ public function project($columns) /** * Set the cursor timeout in seconds. - * - * @param int $seconds + * @param int $seconds * @return $this */ public function timeout($seconds) @@ -167,7 +166,7 @@ public function timeout($seconds) /** * Set the cursor hint. * - * @param mixed $index + * @param mixed $index * @return $this */ public function hint($index) @@ -218,8 +217,8 @@ public function cursor($columns = []) /** * Execute the query as a fresh "select" statement. * - * @param array $columns - * @param bool $returnLazy + * @param array $columns + * @param bool $returnLazy * @return array|static[]|Collection|LazyCollection */ public function getFresh($columns = [], $returnLazy = false) @@ -523,10 +522,10 @@ public function orderBy($column, $direction = 'asc') /** * Add a "where all" clause to the query. * - * @param string $column - * @param array $values - * @param string $boolean - * @param bool $not + * @param string $column + * @param array $values + * @param string $boolean + * @param bool $not * @return $this */ public function whereAll($column, array $values, $boolean = 'and', $not = false) @@ -730,8 +729,8 @@ public function truncate(): bool /** * Get an array with the values of a given column. * - * @param string $column - * @param string $key + * @param string $column + * @param string $key * @return array * * @deprecated @@ -763,9 +762,9 @@ public function raw($expression = null) /** * Append one or more values to an array. * - * @param mixed $column - * @param mixed $value - * @param bool $unique + * @param mixed $column + * @param mixed $value + * @param bool $unique * @return int */ public function push($column, $value = null, $unique = false) @@ -790,8 +789,8 @@ public function push($column, $value = null, $unique = false) /** * Remove one or more values from an array. * - * @param mixed $column - * @param mixed $value + * @param mixed $column + * @param mixed $value * @return int */ public function pull($column, $value = null) @@ -814,7 +813,7 @@ public function pull($column, $value = null) /** * Remove one or more fields. * - * @param mixed $columns + * @param mixed $columns * @return int */ public function drop($columns) @@ -845,8 +844,8 @@ public function newQuery() /** * Perform an update query. * - * @param array $query - * @param array $options + * @param array $query + * @param array $options * @return int */ protected function performUpdate($query, array $options = []) @@ -868,7 +867,7 @@ protected function performUpdate($query, array $options = []) /** * Convert a key to ObjectID if needed. * - * @param mixed $id + * @param mixed $id * @return mixed */ public function convertKey($id) @@ -1002,7 +1001,7 @@ protected function compileWheres() } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereAll(array $where) @@ -1013,7 +1012,7 @@ protected function compileWhereAll(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereBasic(array $where) @@ -1069,7 +1068,7 @@ protected function compileWhereBasic(array $where) } /** - * @param array $where + * @param array $where * @return mixed */ protected function compileWhereNested(array $where) @@ -1080,7 +1079,7 @@ protected function compileWhereNested(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereIn(array $where) @@ -1091,7 +1090,7 @@ protected function compileWhereIn(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereNotIn(array $where) @@ -1102,7 +1101,7 @@ protected function compileWhereNotIn(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereNull(array $where) @@ -1114,7 +1113,7 @@ protected function compileWhereNull(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereNotNull(array $where) @@ -1126,7 +1125,7 @@ protected function compileWhereNotNull(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereBetween(array $where) @@ -1159,7 +1158,7 @@ protected function compileWhereBetween(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereDate(array $where) @@ -1171,7 +1170,7 @@ protected function compileWhereDate(array $where) $operator = $this->conversion[$operator]; - return match ($operator) { + return match($operator) { '=' => [ $column => [ '$gte' => $startOfDay, @@ -1208,7 +1207,7 @@ protected function compileWhereDate(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereMonth(array $where) @@ -1222,7 +1221,7 @@ protected function compileWhereMonth(array $where) '$expr' => [ $operator => [ [ - '$month' => '$'.$column, + '$month' => '$'.$column ], $value, ], @@ -1231,7 +1230,7 @@ protected function compileWhereMonth(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereDay(array $where) @@ -1245,7 +1244,7 @@ protected function compileWhereDay(array $where) '$expr' => [ $operator => [ [ - '$dayOfMonth' => '$'.$column, + '$dayOfMonth' => '$'.$column ], $value, ], @@ -1254,7 +1253,7 @@ protected function compileWhereDay(array $where) } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereYear(array $where) @@ -1267,16 +1266,16 @@ protected function compileWhereYear(array $where) '$expr' => [ $operator => [ [ - '$year' => '$'.$column, + '$year' => '$'.$column ], - $value, + $value ], ], ]; } /** - * @param array $where + * @param array $where * @return array */ protected function compileWhereTime(array $where) @@ -1290,7 +1289,7 @@ protected function compileWhereTime(array $where) } /** - * @param array $where + * @param array $where * @return mixed */ protected function compileWhereRaw(array $where) @@ -1301,7 +1300,7 @@ protected function compileWhereRaw(array $where) /** * Set custom options for the query. * - * @param array $options + * @param array $options * @return $this */ public function options(array $options) From f824ff96f9ecee52e8eedd94e8169226b330e92d Mon Sep 17 00:00:00 2001 From: David Date: Wed, 18 Jan 2023 16:24:16 +0700 Subject: [PATCH 14/14] (+) revert test --- tests/QueryTest.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/QueryTest.php b/tests/QueryTest.php index b8b4eb23e..e1ed7fc12 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -20,12 +20,12 @@ public function setUp(): void User::create(['name' => 'Tommy Toe', 'age' => 33, 'title' => 'user']); User::create(['name' => 'Yvonne Yoe', 'age' => 35, 'title' => 'admin']); User::create(['name' => 'Error', 'age' => null, 'title' => null]); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2020-04-10 10:53:11')->toDateTimeString(), 'time' => '10:53:11']); - Birthday::create(['name' => 'Jane Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:12')->toDateTimeString(), 'time' => '10:53:12']); - Birthday::create(['name' => 'Harry Hoe', 'birthday' => Carbon::parse('2021-05-11 10:53:13')->toDateTimeString(), 'time' => '10:53:13']); - Birthday::create(['name' => 'Robert Doe', 'birthday' => Carbon::parse('2021-05-12 10:53:14')->toDateTimeString(), 'time' => '10:53:14']); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:15')->toDateTimeString(), 'time' => '10:53:15']); - Birthday::create(['name' => 'Mark Moe', 'birthday' => Carbon::parse('2021-05-12 10:53:16')->toDateTimeString(), 'time' => '10:53:16']); + Birthday::create(['name' => 'Mark Moe', 'birthday' => '2020-04-10', 'day' => '10', 'month' => '04', 'year' => '2020', 'time' => '10:53:11']); + Birthday::create(['name' => 'Jane Doe', 'birthday' => '2021-05-12', 'day' => '12', 'month' => '05', 'year' => '2021', 'time' => '10:53:12']); + Birthday::create(['name' => 'Harry Hoe', 'birthday' => '2021-05-11', 'day' => '11', 'month' => '05', 'year' => '2021', 'time' => '10:53:13']); + Birthday::create(['name' => 'Robert Doe', 'birthday' => '2021-05-12', 'day' => '12', 'month' => '05', 'year' => '2021', 'time' => '10:53:14']); + Birthday::create(['name' => 'Mark Moe', 'birthday' => '2021-05-12', 'day' => '12', 'month' => '05', 'year' => '2021', 'time' => '10:53:15']); + Birthday::create(['name' => 'Mark Moe', 'birthday' => '2022-05-12', 'day' => '12', 'month' => '05', 'year' => '2022', 'time' => '10:53:16']); } public function tearDown(): void @@ -183,31 +183,31 @@ public function testWhereDate(): void public function testWhereDay(): void { - $day = Birthday::whereDay('birthday', 12)->get(); + $day = Birthday::whereDay('day', '12')->get(); $this->assertCount(4, $day); - $day = Birthday::whereDay('birthday', 11)->get(); + $day = Birthday::whereDay('day', '11')->get(); $this->assertCount(1, $day); } public function testWhereMonth(): void { - $month = Birthday::whereMonth('birthday', 4)->get(); + $month = Birthday::whereMonth('month', '04')->get(); $this->assertCount(1, $month); - $month = Birthday::whereMonth('birthday', 5)->get(); + $month = Birthday::whereMonth('month', '05')->get(); $this->assertCount(5, $month); } public function testWhereYear(): void { - $year = Birthday::whereYear('birthday', 2021)->get(); + $year = Birthday::whereYear('year', '2021')->get(); $this->assertCount(4, $year); - $year = Birthday::whereYear('birthday', 2022)->get(); + $year = Birthday::whereYear('year', '2022')->get(); $this->assertCount(1, $year); - $year = Birthday::whereYear('birthday', '<', 2021)->get(); + $year = Birthday::whereYear('year', '<', '2021')->get(); $this->assertCount(1, $year); }