Skip to content

Commit 30a281e

Browse files
authored
Merge pull request #475 from opcodesio/fix/logfilecollection-sorting-mutation
Fix LogFileCollection sorting to use idiomatic Laravel .all() method
2 parents 2140b51 + d36c899 commit 30a281e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/LogFileCollection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function sortByEarliestFirst(): self
1414
{
1515
$this->items = $this->sortBy(function (LogFile $file) {
1616
return $file->earliestTimestamp().($file->name ?? '');
17-
}, SORT_NATURAL)->values()->toArray();
17+
}, SORT_NATURAL)->values()->all();
1818

1919
return $this;
2020
}
@@ -23,21 +23,21 @@ public function sortByLatestFirst(): self
2323
{
2424
$this->items = $this->sortByDesc(function (LogFile $file) {
2525
return $file->latestTimestamp().($file->name ?? '');
26-
}, SORT_NATURAL)->values()->toArray();
26+
}, SORT_NATURAL)->values()->all();
2727

2828
return $this;
2929
}
3030

3131
public function sortAlphabeticallyAsc(): self
3232
{
33-
$this->items = $this->sortBy('name')->values()->toArray();
33+
$this->items = $this->sortBy('name')->values()->all();
3434

3535
return $this;
3636
}
3737

3838
public function sortAlphabeticallyDesc(): self
3939
{
40-
$this->items = $this->sortByDesc('name')->values()->toArray();
40+
$this->items = $this->sortByDesc('name')->values()->all();
4141

4242
return $this;
4343
}

src/LogFolderCollection.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public static function fromFiles($files = []): LogFolderCollection
1818

1919
public function sortByEarliestFirst(): self
2020
{
21-
$this->items = $this->sortBy->earliestTimestamp()->values()->toArray();
21+
$this->items = $this->sortBy->earliestTimestamp()->values()->all();
2222

2323
return $this;
2424
}
2525

2626
public function sortByLatestFirst(): self
2727
{
28-
$this->items = $this->sortByDesc->latestTimestamp()->values()->toArray();
28+
$this->items = $this->sortByDesc->latestTimestamp()->values()->all();
2929

3030
return $this;
3131
}
@@ -60,7 +60,7 @@ public function sortAlphabeticallyAsc(): self
6060
return strcmp($a->cleanPath(), $b->cleanPath());
6161
})
6262
->values()
63-
->toArray();
63+
->all();
6464

6565
return $this;
6666
}
@@ -79,7 +79,7 @@ public function sortAlphabeticallyDesc(): self
7979
return strcmp($b->cleanPath(), $a->cleanPath());
8080
})
8181
->values()
82-
->toArray();
82+
->all();
8383

8484
return $this;
8585
}

0 commit comments

Comments
 (0)