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

PageRepository::indexPage()   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\PageRepositoryInterface;
6
use Adminetic\Website\Http\Requests\PageRequest;
7
use Adminetic\Website\Models\Admin\Page;
8
use Illuminate\Support\Facades\Cache;
9
10
class PageRepository implements PageRepositoryInterface
11
{
12
    // Page Index
13
    public function indexPage()
14
    {
15
        $pages = config('adminetic.caching', true)
16
            ? (Cache::has('pages') ? Cache::get('pages') : Cache::rememberForever('pages', function () {
17
                return Page::orderBy('position')->get();
18
            }))
19
            : Page::orderBy('position')->get();
20
21
        return compact('pages');
22
    }
23
24
    // Page Create
25
    public function createPage()
26
    {
27
        //
28
    }
29
30
    // Page Store
31
    public function storePage(PageRequest $request)
32
    {
33
        $page = Page::create($request->validated());
34
        $this->uploadImage($page);
35
    }
36
37
    // Page Show
38
    public function showPage(Page $page)
39
    {
40
        return compact('page');
41
    }
42
43
    // Page Edit
44
    public function editPage(Page $page)
45
    {
46
        return compact('page');
47
    }
48
49
    // Page Update
50
    public function updatePage(PageRequest $request, Page $page)
51
    {
52
        $page->update($request->validated());
53
        $this->uploadImage($page);
54
    }
55
56
    // Page Destroy
57
    public function destroyPage(Page $page)
58
    {
59
        $page->image ? $page->hardDelete('image') : '';
60
        $page->delete();
61
    }
62
63
    // Upload Image
64
    protected function uploadImage(Page $page)
65
    {
66
        if (request()->image) {
67
            $thumbnails = [
68
                'storage' => 'website/page/' . validImageFolder($page->type, 'post'),
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

68
                'storage' => 'website/page/' . /** @scrutinizer ignore-call */ validImageFolder($page->type, 'post'),
Loading history...
69
                'width' => '1200',
70
                'height' => '630',
71
                'quality' => '90',
72
                'thumbnails' => [
73
                    [
74
                        'thumbnail-name' => 'medium',
75
                        'thumbnail-width' => '600',
76
                        'thumbnail-height' => '315',
77
                        'thumbnail-quality' => '70',
78
                    ],
79
                    [
80
                        'thumbnail-name' => 'small',
81
                        'thumbnail-width' => '100',
82
                        'thumbnail-height' => '80',
83
                        'thumbnail-quality' => '30',
84
                    ],
85
                ],
86
            ];
87
            $page->makeThumbnail('image', $thumbnails);
88
        }
89
    }
90
}
91