Skip to content

Commit e22c4a3

Browse files
committed
Refactored IsRevisionable class
1 parent db15fa1 commit e22c4a3

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
}
4444
},
4545
"require-dev": {
46-
"orchestra/testbench": "^v9.0.0"
46+
"orchestra/testbench": "^v9.0.0",
47+
"laravel/pint": "^1.15"
4748
},
4849
"extra": {
4950
"laravel": {

src/Concerns/IsRevisionable.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ public function postUpdate(): void
121121

122122
if (count($revisions) && $maxRevisionCountReached && ($this->revisionCleanup ?? false)) {
123123
foreach ($this->revisionHistory()
124-
->orderBy('id')
125-
->offset($this->historyLimit - 1)
126-
->limit(1000)
127-
->cursor() as $revision) {
124+
->orderBy('id')
125+
->offset($this->historyLimit - 1)
126+
->limit(1000)
127+
->cursor() as $revision) {
128128
$revision->delete();
129129
}
130130
}
131131

132132
$this->insertRevisions($revisions, 'saved');
133133

134-
$this->originalData = null;
135-
$this->updatedData = null;
136-
$this->dirtyData = null;
134+
$this->originalData = [];
135+
$this->updatedData = [];
136+
$this->dirtyData = [];
137137
}
138138

139139
public function revisionHistory(): MorphMany
@@ -290,13 +290,15 @@ public function postForceDelete()
290290
'created_at' => new \DateTime(),
291291
];
292292

293-
Revision::create($revisions);
293+
foreach ($revisions as $revision) {
294+
Revision::create($revision);
295+
}
294296

295297
Event::dispatch('revisionable.deleted', ['model' => $this, 'revisions' => $revisions]);
296298
}
297299
}
298300

299-
public function disableRevisionable()
301+
public function disableRevisionable(): void
300302
{
301303
$this->revisionEnabled = false;
302304
}
@@ -326,7 +328,7 @@ public function getRevisionFormattedFieldNames()
326328
*
327329
* @return string an identifying name for the model
328330
*/
329-
public function identifiableName()
331+
public function identifiableName(): string
330332
{
331333
return $this->getKey();
332334
}
@@ -340,7 +342,7 @@ public function identifiableName()
340342
*
341343
* @return string an identifying name for the model
342344
*/
343-
public function getRevisionNullString()
345+
public function getRevisionNullString(): string
344346
{
345347
return isset($this->revisionNullString) ? $this->revisionNullString : 'nothing';
346348
}
@@ -353,7 +355,7 @@ public function getRevisionNullString()
353355
*
354356
* @return string an identifying name for the model
355357
*/
356-
public function getRevisionUnknownString()
358+
public function getRevisionUnknownString(): string
357359
{
358360
return isset($this->revisionUnknownString) ? $this->revisionUnknownString : 'unknown';
359361
}

0 commit comments

Comments
 (0)