UserAvatarController   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 20%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 26
ccs 3
cts 15
cp 0.2
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A store() 0 20 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
6
use Intervention\Image\Facades\Image;
7
8
class UserAvatarController extends Controller
9
{
10
    /**
11
     * Store a newly created resource in storage.
12
     *
13
     */
14 1
    public function store()
15
    {
16 1
        request()->validate([
17 1
            'file' => ['required', 'image']
18
        ]);
19
        $file = request()
20
            ->file('file')
21
            ->store(config('constants.RELATIVE_AVATAR_PATH'), 'public');
22
23
        Image::make(storage_path('app/public/' . $file))
0 ignored issues
show
Bug introduced by
Are you sure $file of type false|string can be used in concatenation? ( Ignorable by Annotation )

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

23
        Image::make(storage_path('app/public/' . /** @scrutinizer ignore-type */ $file))
Loading history...
24
            ->resize(200, 200, function ($constraint) {
25
                $constraint->aspectRatio();
26
                $constraint->upsize();
27
            })
28
            ->save();
29
30
        auth()->user()->update([
31
            'avatar' => basename($file)
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $path of basename() 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

31
            'avatar' => basename(/** @scrutinizer ignore-type */ $file)
Loading history...
32
        ]);
33
        return response([], 204);
34
    }
35
}
36