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

TestimonialRepository::destroyTestimonial()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Illuminate\Support\Facades\Cache;
6
use Adminetic\Website\Models\Admin\Testimonial;
7
use Adminetic\Website\Http\Requests\TestimonialRequest;
8
use Adminetic\Website\Contracts\TestimonialRepositoryInterface;
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 TestimonialRepository implements TestimonialRepositoryInterface
12
{
13
    // Testimonial Index
14
    public function indexTestimonial()
15
    {
16
        $testimonials = config('adminetic.caching', true)
17
            ? (Cache::has('testimonials') ? Cache::get('testimonials') : Cache::rememberForever('testimonials', function () {
18
                return Testimonial::orderBy('position')->get();
19
            }))
20
            : Testimonial::orderBy('position')->get();
21
        return compact('testimonials');
22
    }
23
24
    // Testimonial Create
25
    public function createTestimonial()
26
    {
27
        //
28
    }
29
30
    // Testimonial Store
31
    public function storeTestimonial(TestimonialRequest $request)
32
    {
33
        $testimonial = Testimonial::create($request->validated());
34
        $this->uploadImage($testimonial);
35
    }
36
37
    // Testimonial Show
38
    public function showTestimonial(Testimonial $testimonial)
39
    {
40
        return compact('testimonial');
41
    }
42
43
    // Testimonial Edit
44
    public function editTestimonial(Testimonial $testimonial)
45
    {
46
        return compact('testimonial');
47
    }
48
49
    // Testimonial Update
50
    public function updateTestimonial(TestimonialRequest $request, Testimonial $testimonial)
51
    {
52
        $testimonial->update($request->validated());
53
        $this->uploadImage($testimonial);
54
    }
55
56
    // Testimonial Destroy
57
    public function destroyTestimonial(Testimonial $testimonial)
58
    {
59
        isset($testimonial->image) ? deleteImage($testimonial->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($testimonial->image) ? /** @scrutinizer ignore-call */ deleteImage($testimonial->image) : '';
Loading history...
60
        $testimonial->delete();
61
    }
62
63
    // Image Upload
64
    protected function uploadImage(Testimonial $testimonial)
65
    {
66
        if (request()->has('image')) {
67
            $testimonial->update([
68
                'image' => request()->image->store('website/testimonial', 'public'),
69
            ]);
70
            $image = Image::make(request()->file('image')->getRealPath());
71
            $image->save(public_path('storage/' . $testimonial->image));
72
        }
73
    }
74
}
75