Code cleanup, no functional changes

This commit is contained in:
2023-06-27 19:39:11 +12:00
parent b70a36003a
commit ad36da0bb1
64 changed files with 466 additions and 438 deletions

View File

@@ -16,11 +16,10 @@ trait SingleOrFail
Builder::macro('singleOrFail',function () {
$result = $this->get();
if (($x=$result->count()) == 1) {
if (($x=$result->count()) === 1)
return $result->first();
}
if ($x == 0)
if ($x === 0)
throw new ModelNotFoundException('Query brings back 0 record(s) called for singleOrFail()');
else
throw new \Exception(sprintf('Query brings back %d record(s) called for singleOrFail()',$x));
@@ -30,9 +29,8 @@ trait SingleOrFail
Builder::macro('single',function () {
$result = $this->get();
if ($result->count() == 1) {
if ($result->count() === 1)
return $result->first();
}
return NULL;
});
@@ -41,11 +39,10 @@ trait SingleOrFail
Builder::macro('singleOrNew',function ($args) {
$result = $this->where($args)->get();
if ($result->count() == 1) {
if ($result->count() === 1)
return $result->first();
}
return $this->newModelInstance($args);
});
}
}
}