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

GetDetailsController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 1
b 0
f 0
dl 0
loc 18
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 4
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