Skip to content

Commit

Permalink
use returns early when result->getRow() === null to reduce deep if
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed May 5, 2020
1 parent f1de4ad commit 6e18227
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions system/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ public function is_not_unique(string $str = null, string $field, array $data): b
if (! preg_match('/\{(\w+)\}/', $where_value))
{
$result = $row->get(null, 0, false);
if ($result->getRow() !== null)
if ($result->getRow() === null)
{
$isNumeric = in_array($result->getFieldData()[0]->type, self::NUMERIC_TYPES, true);
if (! $isNumeric || ($isNumeric && is_numeric($where_value)))
{
$row = $row->where($where_field, $where_value);
}
return false;
}

$isNumeric = in_array($result->getFieldData()[0]->type, self::NUMERIC_TYPES, true);
if (! $isNumeric || ($isNumeric && is_numeric($where_value)))
{
$row = $row->where($where_field, $where_value);
}
}
}
Expand Down Expand Up @@ -263,13 +265,15 @@ public function is_unique(string $str = null, string $field, array $data): bool
if (! preg_match('/\{(\w+)\}/', $ignoreValue))
{
$result = $row->get(null, 0, false);
if ($result->getRow() !== null)
if ($result->getRow() === null)
{
return true;
}

$isNumeric = in_array($result->getFieldData()[0]->type, self::NUMERIC_TYPES, true);
if (! $isNumeric || ($isNumeric && is_numeric($ignoreValue)))
{
$isNumeric = in_array($result->getFieldData()[0]->type, self::NUMERIC_TYPES, true);
if (! $isNumeric || ($isNumeric && is_numeric($ignoreValue)))
{
$row = $row->where("{$ignoreField} !=", $ignoreValue);
}
$row = $row->where("{$ignoreField} !=", $ignoreValue);
}
}
}
Expand Down

0 comments on commit 6e18227

Please sign in to comment.