Skip to content

Commit fdf0248

Browse files
committed
Remove magic extract to use explicit array access to options
1 parent bb1edc5 commit fdf0248

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
@@ -1191,40 +1191,38 @@ protected function compileWhereBetween(array $where): array
11911191
*/
11921192
protected function compileWhereDate(array $where): array
11931193
{
1194-
extract($where);
1195-
1196-
$startOfDay = new UTCDateTime(Carbon::parse($value)->startOfDay());
1197-
$endOfDay = new UTCDateTime(Carbon::parse($value)->endOfDay());
1194+
$startOfDay = new UTCDateTime(Carbon::parse($where['value'])->startOfDay());
1195+
$endOfDay = new UTCDateTime(Carbon::parse($where['value'])->endOfDay());
11981196

1199-
return match($operator) {
1197+
return match($where['operator']) {
12001198
'eq', '=' => [
1201-
$column => [
1199+
$where['column'] => [
12021200
'$gte' => $startOfDay,
12031201
'$lte' => $endOfDay,
12041202
],
12051203
],
12061204
'ne' => [
12071205
'$or' => [
12081206
[
1209-
$column => [
1207+
$where['column'] => [
12101208
'$lt' => $startOfDay,
12111209
],
12121210
],
12131211
[
1214-
$column => [
1212+
$where['column'] => [
12151213
'$gt' => $endOfDay,
12161214
],
12171215
],
12181216
],
12191217
],
12201218
'lt', 'gte' => [
1221-
$column => [
1222-
'$'.$operator => $startOfDay,
1219+
$where['column'] => [
1220+
'$'.$where['operator'] => $startOfDay,
12231221
],
12241222
],
12251223
'gt', 'lte' => [
1226-
$column => [
1227-
'$'.$operator => $endOfDay,
1224+
$where['column'] => [
1225+
'$'.$where['operator'] => $endOfDay,
12281226
],
12291227
],
12301228
};
@@ -1236,17 +1234,13 @@ protected function compileWhereDate(array $where): array
12361234
*/
12371235
protected function compileWhereMonth(array $where): array
12381236
{
1239-
extract($where);
1240-
1241-
$value = (int) ltrim($value, '0');
1242-
12431237
return [
12441238
'$expr' => [
1245-
'$'.$operator => [
1239+
'$'.$where['operator'] => [
12461240
[
1247-
'$month' => '$'.$column,
1241+
'$month' => '$'.$where['column'],
12481242
],
1249-
$value,
1243+
(int) $where['value'],
12501244
],
12511245
],
12521246
];
@@ -1258,17 +1252,13 @@ protected function compileWhereMonth(array $where): array
12581252
*/
12591253
protected function compileWhereDay(array $where): array
12601254
{
1261-
extract($where);
1262-
1263-
$value = (int) ltrim($value, '0');
1264-
12651255
return [
12661256
'$expr' => [
1267-
'$'.$operator => [
1257+
'$'.$where['operator'] => [
12681258
[
1269-
'$dayOfMonth' => '$'.$column,
1259+
'$dayOfMonth' => '$'.$where['column'],
12701260
],
1271-
$value,
1261+
(int) $where['value'],
12721262
],
12731263
],
12741264
];
@@ -1280,17 +1270,13 @@ protected function compileWhereDay(array $where): array
12801270
*/
12811271
protected function compileWhereYear(array $where): array
12821272
{
1283-
extract($where);
1284-
1285-
$value = (int) $value;
1286-
12871273
return [
12881274
'$expr' => [
1289-
'$'.$operator => [
1275+
'$'.$where['operator'] => [
12901276
[
1291-
'$year' => '$'.$column,
1277+
'$year' => '$'.$where['column'],
12921278
],
1293-
$value,
1279+
(int) $where['value'],
12941280
],
12951281
],
12961282
];
@@ -1302,15 +1288,13 @@ protected function compileWhereYear(array $where): array
13021288
*/
13031289
protected function compileWhereTime(array $where): array
13041290
{
1305-
extract($where);
1306-
13071291
return [
13081292
'$expr' => [
1309-
'$'.$operator => [
1293+
'$'.$where['operator'] => [
13101294
[
1311-
'$dateToString' => ['date' => '$'.$column, 'format' => '%H:%M:%S'],
1295+
'$dateToString' => ['date' => '$'.$where['column'], 'format' => '%H:%M:%S'],
13121296
],
1313-
$value,
1297+
$where['value'],
13141298
],
13151299
],
13161300
];

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)