DiscussionList   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 25 2
1
<?php
2
3
namespace Faithgen\Discussions\Http\Resources;
4
5
use FaithGen\SDK\Helpers\ImageHelper;
6
use Illuminate\Http\Resources\Json\JsonResource;
7
use Illuminate\Support\Str;
8
use InnoFlash\LaraStart\Helper;
9
10
class DiscussionList extends JsonResource
11
{
12
    /**
13
     * Transform the resource into an array.
14
     *
15
     * @param  \Illuminate\Http\Request  $request
16
     *
17
     * @return array
18
     */
19
    public function toArray($request)
20
    {
21
        if ($is_admin = Str::of($this->discussable_type)->contains('Ministry')) {
22
            $avatar =
23
                ImageHelper::getImage('profile', $this->discussable->image, config('faithgen-sdk.ministries-server'));
24
        } else {
25
            $avatar = ImageHelper::getImage('users', $this->discussable->image, config('faithgen-sdk.users-server'));
26
        }
27
28
        return [
29
            'id'       => $this->id,
30
            'title'    => $this->title,
31
            'approved' => (bool) $this->approved,
32
            'comments' => [
33
                'count' => $this->comments_count,
34
            ],
35
            'creator'  => [
36
                'id'       => $this->discussable_id,
37
                'name'     => $this->discussable->name,
38
                'is_admin' => $is_admin,
39
                'avatar'   => $avatar,
40
            ],
41
            'date'     => Helper::getDates($this->created_at),
42
        ];
43
    }
44
}
45