Skip to content

Commit 1a5b70e

Browse files
author
Pantea Marius-ciclistu
committed
POC for laravel/framework#31778 bulletproofing incrementOrDecrement
1 parent e450d14 commit 1a5b70e

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Models/BaseModel.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function getCasts()
469469
*/
470470
protected function incrementOrDecrement($column, $amount, $extra, $method): int
471471
{
472-
$return = parent::incrementOrDecrement($column, $amount, $extra, $method);
472+
$return = (int)parent::incrementOrDecrement($column, $amount, $extra, $method);
473473

474474
if ($this->exists) {
475475
$this->incrementsToRefresh[$column] = true;
@@ -782,18 +782,18 @@ protected function performUpdate(Builder $query): bool
782782
// Once we have run the update operation, we will fire the "updated" event for
783783
// this model instance. This will allow developers to hook into these after
784784
// models are updated, giving them a chance to do any special processing.
785-
$dirty = $this->getDirtyForUpdate();
785+
if ([] === $dirty = $this->getDirtyForUpdate()) {
786+
return false;
787+
}
786788

787-
if ([] !== $dirty) {
788-
$this->setKeysForSaveQuery($query)->update($dirty);
789+
$this->setKeysForSaveQuery($query)->update($dirty);
789790

790-
$this->syncChanges();
791+
$this->syncChanges();
791792

792-
$this->tmpDirtyIfAttributesAreSyncedFromCashedCasts = null;
793-
$this->tmpOriginalBeforeAfterEvents = $this->attributes;
793+
$this->tmpDirtyIfAttributesAreSyncedFromCashedCasts = null;
794+
$this->tmpOriginalBeforeAfterEvents = $this->attributes;
794795

795-
$this->fireModelEvent('updated', false);
796-
}
796+
$this->fireModelEvent('updated', false);
797797

798798
return true;
799799
}

0 commit comments

Comments
 (0)