Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — main (#4988)
by Pedro
40:53 queued 25:51
created

SingleBase64Image   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 27
dl 0
loc 54
rs 10
c 1
b 0
f 1
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveRepeatableFile() 0 24 5
A uploadFile() 0 26 5
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Uploads\Uploaders;
4
5
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Facades\Storage;
8
use Illuminate\Support\Str;
9
10
class SingleBase64Image extends Uploader
11
{
12
    public function uploadFile(Model $entry, $value = null)
13
    {
14
        $value = $value ?? CRUD::getRequest()->get($this->name);
0 ignored issues
show
Bug introduced by
The method getRequest() does not exist on Backpack\CRUD\app\Librar...udPanel\CrudPanelFacade. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        $value = $value ?? CRUD::/** @scrutinizer ignore-call */ getRequest()->get($this->name);
Loading history...
15
        $previousImage = $entry->getOriginal($this->name);
16
17
        if (! $value && $previousImage) {
18
            Storage::disk($this->disk)->delete($previousImage);
19
20
            return null;
21
        }
22
23
        if (Str::startsWith($value, 'data:image')) {
24
            if ($previousImage) {
25
                Storage::disk($this->disk)->delete($previousImage);
26
            }
27
28
            $base64Image = Str::after($value, ';base64,');
29
30
            $finalPath = $this->path.$this->getFileNameWithExtension($value);
31
32
            Storage::disk($this->disk)->put($finalPath, base64_decode($base64Image));
33
34
            return $finalPath;
35
        }
36
37
        return $previousImage;
38
    }
39
40
    public function saveRepeatableFile(Model $entry, $value = null)
41
    {
42
        $previousImages = $this->getPreviousRepeatableValues($entry);
43
44
        foreach ($value as $row => $rowValue) {
45
            if ($rowValue) {
46
                if (Str::startsWith($rowValue, 'data:image')) {
47
                    $base64Image = Str::after($rowValue, ';base64,');
48
                    $finalPath = $this->path.$this->getFileNameWithExtension($rowValue);
49
                    Storage::disk($this->disk)->put($finalPath, base64_decode($base64Image));
50
                    $value[$row] = $previousImages[] = $finalPath;
51
52
                    continue;
53
                }
54
            }
55
        }
56
57
        $imagesToDelete = array_diff($previousImages, $value);
58
59
        foreach ($imagesToDelete as $image) {
60
            Storage::disk($this->disk)->delete($image);
61
        }
62
63
        return $value;
64
    }
65
}
66