Passed
Push — master ( b8147c...403ced )
by Curtis
11:47 queued 05:39
created

UserFormIndi::edit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 8
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 14
rs 10
1
<?php
2
3
namespace App\Forms\Builders\enso\core;
4
5
use App\Models\User;
6
use Illuminate\Support\Facades\Auth;
7
use LaravelEnso\Forms\Services\Form;
8
9
class UserFormIndi
10
{
11
    protected const TemplatePath = __DIR__.'/../../../Templates/enso/core/userindi.json';
12
13
    protected const Tooltip = 'Personal information can only be edited via the person form';
14
15
    protected Form $form;
16
17
    public function __construct()
18
    {
19
        $this->form = new Form(self::TemplatePath);
20
    }
21
22
    public function create($person)
23
    {
24
        $this->common($person);
25
26
        return $this->form->value('email', $person->email)
27
            ->value('person_id', $person->id)
28
            ->create();
29
    }
30
31
    public function edit(User $user)
32
    {
33
        $this->common($user->person);
34
35
        if (Auth::user()->can('change-password', $user)) {
36
            $this->form->show([
37
                'password', 'password_confirmation',
38
            ]);
39
        }
40
41
        return $this->form->value('password', null)
42
            ->append('personId', $user->person_id)
43
            ->actions(['back', 'show', 'update'])
44
            ->edit($user);
45
    }
46
47
    protected function common($person)
48
    {
49
        $this->form->value('title', $person->title)
50
            ->value('name', $person->name)
51
            ->value('appellative', $person->appellative)
52
            ->meta('title', 'tooltip', self::Tooltip)
53
            ->meta('name', 'tooltip', self::Tooltip)
54
            ->meta('appellative', 'tooltip', self::Tooltip);
55
    }
56
}
57