CareerRepository   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 79
rs 10
wmc 14

8 Methods

Rating   Name   Duplication   Size   Complexity  
A editCareer() 0 3 1
A storeCareer() 0 4 1
A destroyCareer() 0 3 1
A updateCareer() 0 4 1
A showCareer() 0 3 1
A createCareer() 0 2 1
A indexCareer() 0 9 3
A uploadFiles() 0 24 5
1
<?php
2
3
namespace Adminetic\Website\Repositories;
4
5
use Adminetic\Website\Contracts\CareerRepositoryInterface;
6
use Adminetic\Website\Http\Requests\CareerRequest;
7
use Adminetic\Website\Models\Admin\Career;
8
use Adminetic\Website\Traits\HasFileUpload;
9
use Illuminate\Support\Facades\Cache;
10
11
class CareerRepository implements CareerRepositoryInterface
12
{
13
    use HasFileUpload;
14
15
    // Career Index
16
    public function indexCareer()
17
    {
18
        $careers = config('adminetic.caching', true)
19
            ? (Cache::has('careers') ? Cache::get('careers') : Cache::rememberForever('careers', function () {
20
                return Career::orderBy('position')->get();
21
            }))
22
            : Career::orderBy('position')->get();
23
24
        return compact('careers');
25
    }
26
27
    // Career Create
28
    public function createCareer()
29
    {
30
        //
31
    }
32
33
    // Career Store
34
    public function storeCareer(CareerRequest $request)
35
    {
36
        $career = Career::create($request->validated());
37
        $this->uploadFiles($career);
38
    }
39
40
    // Career Show
41
    public function showCareer(Career $career)
42
    {
43
        return compact('career');
44
    }
45
46
    // Career Edit
47
    public function editCareer(Career $career)
48
    {
49
        return compact('career');
50
    }
51
52
    // Career Update
53
    public function updateCareer(CareerRequest $request, Career $career)
54
    {
55
        $career->update($request->validated());
56
        $this->uploadFiles($career);
57
    }
58
59
    // Career Destroy
60
    public function destroyCareer(Career $career)
61
    {
62
        $career->delete();
63
    }
64
65
    // Upload Files
66
    private function uploadFiles(Career $career)
67
    {
68
        if (request()->has('application_description')) {
69
            $application_description = $this->fileUpload(request()->application_description, 'website/career/'.validImageFolder($career->title), 'application_description');
0 ignored issues
show
Bug introduced by
The function validImageFolder 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

69
            $application_description = $this->fileUpload(request()->application_description, 'website/career/'./** @scrutinizer ignore-call */ validImageFolder($career->title), 'application_description');
Loading history...
Bug introduced by
The property title does not seem to exist on Adminetic\Website\Models\Admin\Career.
Loading history...
70
            $career->update([
71
                'application_description' => $application_description->path,
72
            ]);
73
        }
74
        if (request()->has('application_syllabus')) {
75
            $application_syllabus = $this->fileUpload(request()->application_syllabus, 'website/career/'.validImageFolder($career->title), 'application_syllabus');
76
            $career->update([
77
                'application_syllabus' => $application_syllabus->path,
78
            ]);
79
        }
80
        if (request()->has('application_sort_list')) {
81
            $application_sort_list = $this->fileUpload(request()->application_sort_list, 'website/career/'.validImageFolder($career->title), 'application_sort_list');
82
            $career->update([
83
                'application_sort_list' => $application_sort_list->path,
84
            ]);
85
        }
86
        if (request()->has('application_result')) {
87
            $application_result = $this->fileUpload(request()->application_result, 'website/career/'.validImageFolder($career->title), 'application_result');
88
            $career->update([
89
                'application_result' => $application_result->path,
90
            ]);
91
        }
92
    }
93
}
94