Skip to content

Commit 6e6a82f

Browse files
committed
refactor: remove redundant checks
1 parent 40be8ff commit 6e6a82f

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/Models/Snapshot.php

+10-15
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
use Illuminate\Support\Facades\DB;
1717

1818
/**
19-
* @property-read int $id
20-
* @property int $subject_id
19+
* @property-read positive-int $id
20+
* @property positive-int $subject_id
2121
* @property string $subject_type
22-
* @property Model $stored_attributes
22+
* @property array $stored_attributes
2323
* @property string $version
2424
* @property SnapshotOptions|array $options;
25-
* @property-read Carbon $created_at
26-
* @property-read Carbon $updated_at
25+
* @property Carbon $created_at
26+
* @property Carbon $updated_at
27+
* @property-read Model $subject
2728
*/
2829
class Snapshot extends Model implements SnapshotContract
2930
{
@@ -65,9 +66,7 @@ public function toModel(bool $fillExcludedAttributes = false): Model
6566
{
6667
if ($fillExcludedAttributes) {
6768
/** @var Model $model */
68-
$model = ($this->relationLoaded('subject')
69-
? $this->getRelation('subject') : $this->subject()->firstOrFail()
70-
)->replicate();
69+
$model = $this->subject->replicate();
7170
} else {
7271
/** @var Model $model */
7372
$model = new ($this->getAttribute('subject_type'));
@@ -82,7 +81,7 @@ public function revert(): Model
8281
{
8382
/** @var Model $model */
8483
$model = DB::transaction(function () {
85-
$model = $this->relationLoaded('subject') ? $this->getRelation('subject') : $this->subject()->firstOrFail();
84+
$model = $this->subject;
8685
$model->setRawAttributes($this->getAttribute('stored_attributes'));
8786
$model->save();
8887

@@ -105,9 +104,7 @@ public function branch(): Model
105104
{
106105
/** @var Model $model */
107106
$model = DB::transaction(function () {
108-
$model = ($this->relationLoaded('subject')
109-
? $this->getRelation('subject') : $this->subject()->firstOrFail()
110-
)->replicate();
107+
$model = $this->subject->replicate();
111108
$model->setRawAttributes($this->getAttribute('stored_attributes'));
112109
$model->save();
113110

@@ -130,9 +127,7 @@ public function branch(): Model
130127

131128
public function fork(): Model
132129
{
133-
$model = ($this->relationLoaded('subject')
134-
? $this->getRelation('subject') : $this->subject()->firstOrFail()
135-
)->replicate();
130+
$model = $this->subject->replicate();
136131
$model->setRawAttributes($this->getAttribute('stored_attributes'));
137132
$model->save();
138133

0 commit comments

Comments
 (0)