Skip to content

Commit 650fd1f

Browse files
authored
Merge pull request #8565 from kenjis/refactor-Model-useCasts
[4.5] refactor: use local variables in Model
2 parents 0d8418e + 570175a commit 650fd1f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

system/Model.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ protected function doFind(bool $singleton, $id = null)
186186
{
187187
$builder = $this->builder();
188188

189-
if ($this->useCasts()) {
189+
$useCast = $this->useCasts();
190+
if ($useCast) {
190191
$returnType = $this->tempReturnType;
191192
$this->asArray();
192193
}
@@ -207,7 +208,7 @@ protected function doFind(bool $singleton, $id = null)
207208
$row = $builder->get()->getResult($this->tempReturnType);
208209
}
209210

210-
if ($this->useCasts()) {
211+
if ($useCast) {
211212
$row = $this->convertToReturnType($row, $returnType);
212213

213214
$this->tempReturnType = $returnType;
@@ -257,7 +258,8 @@ protected function doFindAll(?int $limit = null, int $offset = 0)
257258

258259
$builder = $this->builder();
259260

260-
if ($this->useCasts()) {
261+
$useCast = $this->useCasts();
262+
if ($useCast) {
261263
$returnType = $this->tempReturnType;
262264
$this->asArray();
263265
}
@@ -270,7 +272,7 @@ protected function doFindAll(?int $limit = null, int $offset = 0)
270272
->get()
271273
->getResult($this->tempReturnType);
272274

273-
if ($this->useCasts()) {
275+
if ($useCast) {
274276
foreach ($results as $i => $row) {
275277
$results[$i] = $this->convertToReturnType($row, $returnType);
276278
}
@@ -293,7 +295,8 @@ protected function doFirst()
293295
{
294296
$builder = $this->builder();
295297

296-
if ($this->useCasts()) {
298+
$useCast = $this->useCasts();
299+
if ($useCast) {
297300
$returnType = $this->tempReturnType;
298301
$this->asArray();
299302
}
@@ -312,7 +315,7 @@ protected function doFirst()
312315

313316
$row = $builder->limit(1, 0)->get()->getFirstRow($this->tempReturnType);
314317

315-
if ($this->useCasts()) {
318+
if ($useCast) {
316319
$row = $this->convertToReturnType($row, $returnType);
317320

318321
$this->tempReturnType = $returnType;

0 commit comments

Comments
 (0)