Passed
Push — main ( 86a6dd...ec1f24 )
by PRATIK
03:12
created

TeamRepository::showTeam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Adminetic\Website\Contracts\TeamRepositoryInterface;
6
use Adminetic\Website\Http\Requests\TeamRequest;
7
use Adminetic\Website\Models\Admin\Team;
8
use Illuminate\Support\Facades\Cache;
9
10
class TeamRepository implements TeamRepositoryInterface
11
{
12
    // Team Index
13
    public function indexTeam()
14
    {
15
        $teams = config('adminetic.caching', true)
16
            ? (Cache::has('teams') ? Cache::get('teams') : Cache::rememberForever('teams', function () {
17
                return Team::orderBy('position')->get();
18
            }))
19
            : Team::orderBy('position')->get();
20
21
        return compact('teams');
22
    }
23
24
    // Team Create
25
    public function createTeam()
26
    {
27
        //
28
    }
29
30
    // Team Store
31
    public function storeTeam(TeamRequest $request)
32
    {
33
        $team = Team::create($request->validated());
34
        $this->uploadImage($team);
35
    }
36
37
    // Team Show
38
    public function showTeam(Team $team)
39
    {
40
        return compact('team');
41
    }
42
43
    // Team Edit
44
    public function editTeam(Team $team)
45
    {
46
        return compact('team');
47
    }
48
49
    // Team Update
50
    public function updateTeam(TeamRequest $request, Team $team)
51
    {
52
        $team->update($request->validated());
53
        $this->uploadImage($team);
54
    }
55
56
    // Team Destroy
57
    public function destroyTeam(Team $team)
58
    {
59
        isset($team->image) ? $team->hardDelete('image') : '';
60
        $team->delete();
61
    }
62
63
    protected function uploadImage(Team $team)
64
    {
65
        if (request()->image) {
66
            $thumbnails = [
67
                'storage' => 'website/team/' . validImageFolder($team->name, 'default'),
0 ignored issues
show
Bug introduced by
The function validImageFolder was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
                'storage' => 'website/team/' . /** @scrutinizer ignore-call */ validImageFolder($team->name, 'default'),
Loading history...
68
                'width' => '600',
69
                'height' => '400',
70
                'quality' => '90',
71
                'thumbnails' => [
72
                    [
73
                        'thumbnail-name' => 'medium',
74
                        'thumbnail-width' => '300',
75
                        'thumbnail-height' => '200',
76
                        'thumbnail-quality' => '70',
77
                    ],
78
                    [
79
                        'thumbnail-name' => 'small',
80
                        'thumbnail-width' => '150',
81
                        'thumbnail-height' => '100',
82
                        'thumbnail-quality' => '50',
83
                    ],
84
                ],
85
            ];
86
            $team->makeThumbnail('image', $thumbnails);
87
        }
88
    }
89
}
90