Skip to content

Commit 35b612b

Browse files
committed
refactor: early return
Complex conditions cause bugs.
1 parent a0a55ed commit 35b612b

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

system/Model.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,15 @@ public function set($key, $value = '', ?bool $escape = null)
584584
*/
585585
protected function shouldUpdate($data): bool
586586
{
587+
if (parent::shouldUpdate($data) === false) {
588+
return false;
589+
}
590+
587591
// When useAutoIncrement feature is disabled, check
588592
// in the database if given record already exists
589-
return parent::shouldUpdate($data)
590-
&& ($this->useAutoIncrement
593+
return $this->useAutoIncrement
591594
? true
592-
: $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1);
595+
: $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1;
593596
}
594597

595598
/**

0 commit comments

Comments
 (0)