Skip to content

Commit

Permalink
refactor: early return
Browse files Browse the repository at this point in the history
Complex conditions cause bugs.
  • Loading branch information
kenjis committed Dec 6, 2021
1 parent a0a55ed commit 35b612b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,15 @@ public function set($key, $value = '', ?bool $escape = null)
*/
protected function shouldUpdate($data): bool
{
if (parent::shouldUpdate($data) === false) {
return false;
}

// When useAutoIncrement feature is disabled, check
// in the database if given record already exists
return parent::shouldUpdate($data)
&& ($this->useAutoIncrement
return $this->useAutoIncrement
? true
: $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1);
: $this->where($this->primaryKey, $this->getIdValue($data))->countAllResults() === 1;
}

/**
Expand Down

0 comments on commit 35b612b

Please sign in to comment.