Skip to content

Commit

Permalink
Parameter #2 $callback of function tap expects (callable(int): void)|…
Browse files Browse the repository at this point in the history
…null, Closure(bool|null): void given.
  • Loading branch information
LastDragon-ru committed Aug 14, 2021
1 parent fa3602e commit c685c20
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions packages/eloquent/src/Concerns/SaveOrThrow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,36 @@

use Exception;
use Illuminate\Database\Eloquent\Model;

use function tap;
use Illuminate\Database\Eloquent\Relations\Pivot;

/**
* @mixin Model
* @mixin Model|Pivot
*/
trait SaveOrThrow {
/**
* @inheritdoc
*/
public function save(array $options = []) {
return tap(parent::save($options), static function (bool $result): void {
if (!$result) {
throw new Exception('An unknown error occurred while saving the model.');
}
});
$result = parent::save($options);

if (!$result) {
throw new Exception('An unknown error occurred while saving the model.');
}

return $result;
}

/**
* @inheritdoc
*/
public function delete() {
return tap(parent::delete(), static function (?bool $result): void {
if ($result === false) {
throw new Exception('An unknown error occurred while deleting the model.');
}
});
/** @var bool|int|false $result */
$result = parent::delete();

if ($result === false) {
throw new Exception('An unknown error occurred while deleting the model.');
}

return $result;
}
}

0 comments on commit c685c20

Please sign in to comment.