Test Setup Failed
Push — master ( 811519...394087 )
by guillaume
11:21 queued 05:26
created

ProfileController::showEditProfile()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
4
namespace App\Http\Controllers;
5
6
7
use App\Src\UseCases\Domain\Users\EditUser;
8
use App\Src\UseCases\Domain\Users\GetUser;
9
use App\Src\UseCases\Organizations\GetOrganization;
10
use Illuminate\Http\Request;
11
use Illuminate\Support\Facades\Auth;
12
13
class ProfileController extends Controller
14
{
15
    public function showEditProfile(GetUser $getUser, GetOrganization $getOrganization)
16
    {
17
        $user = $getUser->get(Auth::user()->uuid);
0 ignored issues
show
Bug Best Practice introduced by
The property uuid does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
18
        if($user->organizationId() !== null) {
19
            $organization = $getOrganization->get($user->organizationId());
20
        }
21
        return view('users/edit_form', [
22
            'user' => $user->toArray(),
23
            'organization' => isset($organization) ? $organization->toArray() : null,
24
            'action' => route('user.edit.profile')
25
        ]);
26
    }
27
28
    public function processEditProfile(Request $request, EditUser $editUser)
29
    {
30
        $userId = Auth::user()->uuid;
0 ignored issues
show
Bug Best Practice introduced by
The property uuid does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
31
        $firstname = $request->input('firstname') !== null ? $request->input('firstname') : '';
32
        $lastname = $request->input('lastname') !== null ? $request->input('lastname') : '';
33
        $email = $request->input('email') !== null ? $request->input('email') : '';
34
        $picture = [];
35
        if($request->has('logo')){
36
            $picture['path_picture'] = $request->file('logo')->path();
37
            $picture['original_name'] = $request->file('logo')->getClientOriginalName();
38
            $picture['mine_type'] = $request->file('logo')->getMimeType();
39
        }
40
        $editUser->edit($userId, $email, $firstname, $lastname, $picture);
41
        $request->session()->flash('notif_msg', 'Mise à jour de votre profil réussie');
42
        return redirect()->back();
43
    }
44
}
45