Passed
Push — dev6 ( 735134...809e49 )
by Ron
15:35
created

UploadImageController::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Http\Controllers\Home;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\Home\UploadImageRequest;
7
use Illuminate\Http\File;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Log;
10
use Illuminate\Support\Facades\Storage;
11
12
class UploadImageController extends Controller
13
{
14
    /**
15
     *  Upload an image that will be used in a text editor field
16
     */
17
    public function __invoke(UploadImageRequest $request)
18
    {
19
        //  Storage Path
20
        $path = 'images/uploaded';
21
        $location = Storage::disk('public')->putFile($path, new File($request->file));
22
23
        Log::channel('user')->info('New image uploaded by '.$request->user()->username, $request->toArray());
24
25
        return Storage::url($location);
1 ignored issue
show
Bug introduced by
It seems like $location can also be of type false; however, parameter $path of Illuminate\Support\Facades\Storage::url() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

25
        return Storage::url(/** @scrutinizer ignore-type */ $location);
Loading history...
26
    }
27
}
28