Skip to content

Commit df61841

Browse files
committed
Remove magic extract to use explicit array access to options
1 parent adfcb94 commit df61841

File tree

2 files changed

+23
-39
lines changed

2 files changed

+23
-39
lines changed

src/Query/Builder.php

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,40 +1182,38 @@ protected function compileWhereBetween(array $where): array
11821182
*/
11831183
protected function compileWhereDate(array $where): array
11841184
{
1185-
extract($where);
1186-
1187-
$startOfDay = new UTCDateTime(Carbon::parse($value)->startOfDay());
1188-
$endOfDay = new UTCDateTime(Carbon::parse($value)->endOfDay());
1185+
$startOfDay = new UTCDateTime(Carbon::parse($where['value'])->startOfDay());
1186+
$endOfDay = new UTCDateTime(Carbon::parse($where['value'])->endOfDay());
11891187

1190-
return match($operator) {
1188+
return match($where['operator']) {
11911189
'eq', '=' => [
1192-
$column => [
1190+
$where['column'] => [
11931191
'$gte' => $startOfDay,
11941192
'$lte' => $endOfDay,
11951193
],
11961194
],
11971195
'ne' => [
11981196
'$or' => [
11991197
[
1200-
$column => [
1198+
$where['column'] => [
12011199
'$lt' => $startOfDay,
12021200
],
12031201
],
12041202
[
1205-
$column => [
1203+
$where['column'] => [
12061204
'$gt' => $endOfDay,
12071205
],
12081206
],
12091207
],
12101208
],
12111209
'lt', 'gte' => [
1212-
$column => [
1213-
'$'.$operator => $startOfDay,
1210+
$where['column'] => [
1211+
'$'.$where['operator'] => $startOfDay,
12141212
],
12151213
],
12161214
'gt', 'lte' => [
1217-
$column => [
1218-
'$'.$operator => $endOfDay,
1215+
$where['column'] => [
1216+
'$'.$where['operator'] => $endOfDay,
12191217
],
12201218
],
12211219
};
@@ -1227,17 +1225,13 @@ protected function compileWhereDate(array $where): array
12271225
*/
12281226
protected function compileWhereMonth(array $where): array
12291227
{
1230-
extract($where);
1231-
1232-
$value = (int) ltrim($value, '0');
1233-
12341228
return [
12351229
'$expr' => [
1236-
'$'.$operator => [
1230+
'$'.$where['operator'] => [
12371231
[
1238-
'$month' => '$'.$column,
1232+
'$month' => '$'.$where['column'],
12391233
],
1240-
$value,
1234+
(int) $where['value'],
12411235
],
12421236
],
12431237
];
@@ -1249,17 +1243,13 @@ protected function compileWhereMonth(array $where): array
12491243
*/
12501244
protected function compileWhereDay(array $where): array
12511245
{
1252-
extract($where);
1253-
1254-
$value = (int) ltrim($value, '0');
1255-
12561246
return [
12571247
'$expr' => [
1258-
'$'.$operator => [
1248+
'$'.$where['operator'] => [
12591249
[
1260-
'$dayOfMonth' => '$'.$column,
1250+
'$dayOfMonth' => '$'.$where['column'],
12611251
],
1262-
$value,
1252+
(int) $where['value'],
12631253
],
12641254
],
12651255
];
@@ -1271,17 +1261,13 @@ protected function compileWhereDay(array $where): array
12711261
*/
12721262
protected function compileWhereYear(array $where): array
12731263
{
1274-
extract($where);
1275-
1276-
$value = (int) $value;
1277-
12781264
return [
12791265
'$expr' => [
1280-
'$'.$operator => [
1266+
'$'.$where['operator'] => [
12811267
[
1282-
'$year' => '$'.$column,
1268+
'$year' => '$'.$where['column'],
12831269
],
1284-
$value,
1270+
(int) $where['value'],
12851271
],
12861272
],
12871273
];
@@ -1293,15 +1279,13 @@ protected function compileWhereYear(array $where): array
12931279
*/
12941280
protected function compileWhereTime(array $where): array
12951281
{
1296-
extract($where);
1297-
12981282
return [
12991283
'$expr' => [
1300-
'$'.$operator => [
1284+
'$'.$where['operator'] => [
13011285
[
1302-
'$dateToString' => ['date' => '$'.$column, 'format' => '%H:%M:%S'],
1286+
'$dateToString' => ['date' => '$'.$where['column'], 'format' => '%H:%M:%S'],
13031287
],
1304-
$value,
1288+
$where['value'],
13051289
],
13061290
],
13071291
];

tests/Models/Birthday.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Birthday extends Eloquent
1717
{
1818
protected $connection = 'mongodb';
1919
protected $collection = 'birthday';
20-
protected $fillable = ['name', 'birthday', 'time'];
20+
protected $fillable = ['name', 'birthday'];
2121

2222
protected $casts = [
2323
'birthday' => 'datetime',

0 commit comments

Comments
 (0)