Passed
Push — main ( 86a6dd...ec1f24 )
by PRATIK
03:12
created

ClientRepository::indexClient()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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