Passed
Push — main ( 81a08a...d746a9 )
by PRATIK
13:24
created

FeatureRepository::createFeature()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

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