Passed
Push — main ( 0c0937...7a01df )
by PRATIK
03:45
created

BlockRepository   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 61
rs 10
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A editBlock() 0 3 1
A createBlock() 0 2 1
A updateBlock() 0 4 1
A showBlock() 0 3 1
A indexBlock() 0 8 3
A storeBlock() 0 4 1
A uploadImage() 0 8 2
A destroyBlock() 0 4 2
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Illuminate\Support\Facades\Cache;
6
use Adminetic\Website\Models\Admin\Block;
7
use Adminetic\Website\Http\Requests\BlockRequest;
8
use Adminetic\Website\Contracts\BlockRepositoryInterface;
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 BlockRepository implements BlockRepositoryInterface
12
{
13
    // Block Index
14
    public function indexBlock()
15
    {
16
        $blocks = config('adminetic.caching', true)
17
            ? (Cache::has('blocks') ? Cache::get('blocks') : Cache::rememberForever('blocks', function () {
18
                return Block::orderBy('position')->get();
19
            }))
20
            : Block::orderBy('position')->get();
21
        return compact('blocks');
22
    }
23
24
    // Block Create
25
    public function createBlock()
26
    {
27
        //
28
    }
29
30
    // Block Store
31
    public function storeBlock(BlockRequest $request)
32
    {
33
        $block = Block::create($request->validated());
34
        $this->uploadImage($block);
35
    }
36
37
    // Block Show
38
    public function showBlock(Block $block)
39
    {
40
        return compact('block');
41
    }
42
43
    // Block Edit
44
    public function editBlock(Block $block)
45
    {
46
        return compact('block');
47
    }
48
49
    // Block Update
50
    public function updateBlock(BlockRequest $request, Block $block)
51
    {
52
        $block->update($request->validated());
53
        $this->uploadImage($block);
54
    }
55
56
    // Block Destroy
57
    public function destroyBlock(Block $block)
58
    {
59
        isset($block->image) ? deleteImage($block->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($block->image) ? /** @scrutinizer ignore-call */ deleteImage($block->image) : '';
Loading history...
60
        $block->delete();
61
    }
62
63
    // Image Upload
64
    protected function uploadImage(Block $block)
65
    {
66
        if (request()->has('image')) {
67
            $block->update([
68
                'image' => request()->image->store('website/block', 'public'),
69
            ]);
70
            $image = Image::make(request()->file('image')->getRealPath());
71
            $image->save(public_path('storage/' . $block->image));
72
        }
73
    }
74
}
75