Passed
Push — main ( 21b81c...b80092 )
by PRATIK
14:07
created

PopupRepository::showPopup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Illuminate\Support\Facades\Cache;
6
use Adminetic\Website\Models\Admin\Popup;
7
use Adminetic\Website\Http\Requests\PopupRequest;
8
use Adminetic\Website\Contracts\PopupRepositoryInterface;
9
use Intervention\Image\Facades\Image;
0 ignored issues
show
Bug introduced by
The type Intervention\Image\Facades\Image was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class PopupRepository implements PopupRepositoryInterface
12
{
13
    // Popup Index
14
    public function indexPopup()
15
    {
16
        $popups = config('adminetic.caching', true)
17
            ? (Cache::has('popups') ? Cache::get('popups') : Cache::rememberForever('popups', function () {
18
                return Popup::latest()->get();
19
            }))
20
            : Popup::latest()->get();
21
        return compact('popups');
22
    }
23
24
    // Popup Create
25
    public function createPopup()
26
    {
27
        //
28
    }
29
30
    // Popup Store
31
    public function storePopup(PopupRequest $request)
32
    {
33
        $popup = Popup::create($request->validated());
34
        $this->uploadImage($popup);
35
    }
36
37
    // Popup Show
38
    public function showPopup(Popup $popup)
39
    {
40
        return compact('popup');
41
    }
42
43
    // Popup Edit
44
    public function editPopup(Popup $popup)
45
    {
46
        return compact('popup');
47
    }
48
49
    // Popup Update
50
    public function updatePopup(PopupRequest $request, Popup $popup)
51
    {
52
        $popup->update($request->validated());
53
        $this->uploadImage($popup);
54
    }
55
56
    // Popup Destroy
57
    public function destroyPopup(Popup $popup)
58
    {
59
        isset($popup->image) ? deleteImage($popup->image) : '';
0 ignored issues
show
Bug introduced by
The function deleteImage 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

59
        isset($popup->image) ? /** @scrutinizer ignore-call */ deleteImage($popup->image) : '';
Loading history...
60
        $popup->delete();
61
    }
62
63
    protected function uploadImage(Popup $popup)
64
    {
65
        if (request()->has('image')) {
66
            $popup->update([
67
                'image' => request()->image->store('website/popup', 'public')
68
            ]);
69
            if (request()->file('image')->getClientOriginalExtension() == 'gif') {
70
                $imageName = time() . '.' . request()->image->extension();
71
72
                request()->image->move(public_path('website/popup'), $imageName);
73
            } else {
74
                $image = Image::make(request()->file('image')->getRealPath());
75
                $image->save(public_path('storage/' . $popup->image));
76
            }
77
        }
78
    }
79
}
80