PostAuthors::all()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 14
rs 10
1
<?php
2
3
namespace App\Services;
4
5
use App\Models\Post;
6
use App\Models\User;
7
8
class PostAuthors
9
{
10
    /**
11
     * Get all the authors as a collection.
12
     *
13
     * @return
14
     */
15
    public static function all()
16
    {
17
        $usernames = User::userNames()->get();
18
        $authors = Post::authors()->get();
19
        $allAvailableAuthors = collect([]);
20
21
        foreach ($authors as $author) {
22
            $allAvailableAuthors[] = $author->author;
23
        }
24
        foreach ($usernames as $username) {
25
            $allAvailableAuthors[] = $username->name;
26
        }
27
28
        return $allAvailableAuthors->unique()->sort()->all();
29
    }
30
}
31