| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace WPIDE\App\Utils; |
| 4 | 4 | |
| 5 | +use WPIDE\App\Services\Storage\DirectoryCollection; | |
| 6 | + | |
| 5 | 7 | trait Collection |
| 6 | 8 | { |
| 7 | 9 | protected $items = []; |
| 8 | 10 | |
| @@ -41,9 +43,9 @@ | ||
| 41 | 43 | { |
| 42 | 44 | return $this->items; |
| 43 | 45 | } |
| 44 | 46 | |
| 45 | - public function filter(callable $callback) | |
| 47 | + public function filter(callable $callback): DirectoryCollection | |
| 46 | 48 | { |
| 47 | 49 | $this->items = array_filter($this->items, $callback); |
| 48 | 50 | |
| 49 | 51 | return $this; |
| @@ -48,9 +50,9 @@ | ||
| 48 | 50 | |
| 49 | 51 | return $this; |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | - public function map(callable $callback) | |
| 54 | + public function map(callable $callback): DirectoryCollection | |
| 53 | 55 | { |
| 54 | 56 | $this->items = array_map($callback, $this->items); |
| 55 | 57 | |
| 56 | 58 | return $this; |
| @@ -55,17 +57,23 @@ | ||
| 55 | 57 | |
| 56 | 58 | return $this; |
| 57 | 59 | } |
| 58 | 60 | |
| 59 | - public function merge($collection) { | |
| 61 | + public function merge($collection): DirectoryCollection | |
| 62 | + { | |
| 60 | 63 | |
| 61 | 64 | $this->items = array_merge($this->items, $collection->items); |
| 65 | + | |
| 66 | + return $this; | |
| 62 | 67 | } |
| 63 | 68 | |
| 64 | - public function sortByValue($value, $desc = false) | |
| 69 | + public function sortByValue($value, $desc = false): DirectoryCollection | |
| 65 | 70 | { |
| 71 | + | |
| 66 | 72 | usort($this->items, function ($a, $b) use ($value) { |
| 67 | - return $a[$value] <=> $b[$value]; | |
| 73 | + return | |
| 74 | + ($a['type'] <=> $b['type']) * 1000 + | |
| 75 | + ($a[$value] <=> $b[$value]); | |
| 68 | 76 | }); |
| 69 | 77 | |
| 70 | 78 | if ($desc) { |
| 71 | 79 | $this->items = array_reverse($this->items); |