Passed
Push — dev6 ( 65456c...37607e )
by Ron
19:01
created

GetDetailsController::__invoke()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 13
rs 9.9332
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\TechTipBookmark;
9
10
class GetDetailsController extends Controller
11
{
12
    /**
13
     * Get the Admin Details of a Tech Tip
14
     */
15
    public function __invoke($tipId)
16
    {
17
        $tip       = TechTip::find($tipId);
18
        $favorites = TechTipBookmark::where('tip_id', $tipId)->count();
19
20
        return [
21
            'author'      => $tip->CreatedBy->full_name,
22
            'dateCreated' => date('M d, Y', strtotime($tip->created_at)),
23
            'lastEdited'  => $tip->updated_id !== null ? date('M d, Y', strtotime($tip->updated_at)) : null,
24
            'editedBy'    => $tip->updated_id !== null ? $tip->UpdatedBy->full_name : null,
25
            'views'       => $tip->views,
26
            'favorites'   => $favorites,
27
            'isPinned'    => $tip->sticky ? 'Yes' : 'No',
28
        ];
29
    }
30
}
31