Passed
Push — main ( 6877e3...35b0cf )
by PRATIK
04:14
created

ProjectRepository::updateProject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Adminetic\Website\Contracts\ProjectRepositoryInterface;
6
use Adminetic\Website\Http\Requests\ProjectRequest;
7
use Adminetic\Website\Models\Admin\Project;
8
use Illuminate\Support\Facades\Cache;
9
10
class ProjectRepository implements ProjectRepositoryInterface
11
{
12
    // Project Index
13
    public function indexProject()
14
    {
15
        $projects = config('adminetic.caching', true)
16
            ? (Cache::has('projects') ? Cache::get('projects') : Cache::rememberForever('projects', function () {
17
                return Project::latest()->get();
18
            }))
19
            : Project::latest()->get();
20
21
        return compact('projects');
22
    }
23
24
    // Project Create
25
    public function createProject()
26
    {
27
        //
28
    }
29
30
    // Project Store
31
    public function storeProject(ProjectRequest $request)
32
    {
33
        $project = Project::create($request->validated());
34
        $this->uploadImage($project);
35
    }
36
37
    // Project Show
38
    public function showProject(Project $project)
39
    {
40
        return compact('project');
41
    }
42
43
    // Project Edit
44
    public function editProject(Project $project)
45
    {
46
        return compact('project');
47
    }
48
49
    // Project Update
50
    public function updateProject(ProjectRequest $request, Project $project)
51
    {
52
        $project->update($request->validated());
53
        $this->uploadImage($project);
54
    }
55
56
    // Project Destroy
57
    public function destroyProject(Project $project)
58
    {
59
        isset($project->image) ? $project->hardDelete('image') : '';
60
        $project->delete();
61
    }
62
63
    // Upload Image
64
    protected function uploadImage(Project $project)
65
    {
66
        if (request()->image) {
67
            $thumbnails = [
68
                'storage' => 'website/project/' . validImageFolder($project->type, 'post'),
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

68
                'storage' => 'website/project/' . /** @scrutinizer ignore-call */ validImageFolder($project->type, 'post'),
Loading history...
Bug introduced by
The property type does not seem to exist on Adminetic\Website\Models\Admin\Project.
Loading history...
69
                'width' => '1200',
70
                'height' => '630',
71
                'quality' => '100',
72
                'thumbnails' => [
73
                    [
74
                        'thumbnail-name' => 'medium',
75
                        'thumbnail-width' => '600',
76
                        'thumbnail-height' => '315',
77
                        'thumbnail-quality' => '80',
78
                    ],
79
                    [
80
                        'thumbnail-name' => 'small',
81
                        'thumbnail-width' => '100',
82
                        'thumbnail-height' => '80',
83
                        'thumbnail-quality' => '50',
84
                    ],
85
                ],
86
            ];
87
            $project->makeThumbnail('image', $thumbnails);
88
        }
89
    }
90
}
91