Passed
Push — master ( d487d9...59950a )
by Ron
02:58 queued 12s
created

GetTipDetailsController::__invoke()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 15
rs 9.9
c 1
b 0
f 0
cc 4
nc 8
nop 1
1
<?php
2
3
namespace App\Http\Controllers\TechTips;
4
5
use App\Http\Controllers\Controller;
6
7
use App\Models\TechTip;
8
use App\Models\UserTechTipBookmark;
9
10
class GetTipDetailsController extends Controller
11
{
12
    /**
13
     * Get Admin details of a Tech Tip
14
     */
15
    public function __invoke($tipId)
16
    {
17
        $this->authorize('manage', TechTip::class);
18
19
        $tip       = TechTip::find($tipId);
20
        $favorites = UserTechTipBookmark::where('tip_id', $tipId)->count();
21
22
        return [
23
            'author'      => $tip->CreatedBy->full_name,
24
            'dateCreated' => date('M d, Y', strtotime($tip->created_at)),
25
            'lastEdited'  => $tip->updated_id !== null ? date('M d, Y', strtotime($tip->updated_at)) : null,
26
            'editedBy'    => $tip->updated_id !== null ? $tip->UpdatedBy->full_name : null,
27
            'views'       => $tip->views,
28
            'favorites'   => $favorites,
29
            'isPinned'    => $tip->sticky ? 'Yes' : 'No',
30
        ];
31
    }
32
}
33