Comment::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
cc 2
eloc 13
c 4
b 1
f 1
nc 2
nop 1
dl 0
loc 18
rs 9.8333
1
<?php
2
3
namespace FaithGen\SDK\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 Comment 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->creatable_type)->contains('Ministry')) {
0 ignored issues
show
Bug Best Practice introduced by
The property creatable_type does not exist on FaithGen\SDK\Http\Resources\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
            $avatar = ImageHelper::getImage('profile', $this->creatable->image, config('faithgen-sdk.ministries-server'));
0 ignored issues
show
Bug Best Practice introduced by
The property creatable does not exist on FaithGen\SDK\Http\Resources\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
        } else {
24
            $avatar = ImageHelper::getImage('users', $this->creatable->image, config('faithgen-sdk.users-server'));
25
        }
26
27
        return [
28
            'id'      => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on FaithGen\SDK\Http\Resources\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
            'comment' => $this->comment,
0 ignored issues
show
Bug Best Practice introduced by
The property comment does not exist on FaithGen\SDK\Http\Resources\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
            'creator' => [
31
                'id'       => $this->creatable->id,
32
                'name'     => $this->creatable->name,
33
                'is_admin' => $is_admin,
34
                'avatar'   => $avatar,
35
            ],
36
            'date'    => Helper::getDates($this->created_at),
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on FaithGen\SDK\Http\Resources\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
        ];
38
    }
39
}
40