Skip to content

Commit 0ed18df

Browse files
committed
Refactor addWhere() method in UniqueTranslationValidator
1 parent 47041cf commit 0ed18df

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/UniqueTranslationValidator.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,22 @@ protected function addConditions($query, $conditions)
326326
* @param string $key
327327
* @param string $extraValue
328328
*
329-
* @return void
329+
* @return \Illuminate\Database\Query\Builder
330330
*/
331331
protected function addWhere($query, $key, $extraValue)
332332
{
333333
if ($extraValue === 'NULL') {
334-
$query->whereNull($key);
335-
} elseif ($extraValue === 'NOT_NULL') {
336-
$query->whereNotNull($key);
337-
} elseif (Str::startsWith($extraValue, '!')) {
338-
$query->where($key, '!=', mb_substr($extraValue, 1));
339-
} else {
340-
$query->where($key, $extraValue);
334+
return $query->whereNull($key);
335+
}
336+
337+
if ($extraValue === 'NOT_NULL') {
338+
return $query->whereNotNull($key);
341339
}
340+
341+
$isNegative = Str::startsWith($extraValue, '!');
342+
$operator = $isNegative ? '!=' : '=';
343+
$value = $isNegative ? mb_substr($extraValue, 1) : $extraValue;
344+
345+
return $query->where($key, $operator, $value);
342346
}
343347
}

0 commit comments

Comments
 (0)