PermissionForm::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Forms;
6
7
use Illuminate\Validation\Rule;
8
use Livewire\Form;
9
use Spatie\Permission\Models\Permission;
10
11
class PermissionForm extends Form
12
{
13
    /**
14
     * The permission to update.
15
     *
16
     * @var Permission|null
17
     */
18
    public ?Permission $permission = null;
19
20
    /**
21
     * The name of the permission.
22
     *
23
     * @var string|null
24
     */
25
    public ?string $name = null;
26
27
    /**
28
     * The description of the permission.
29
     *
30
     * @var string|null
31
     */
32
    public ?string $description = null;
33
34
    protected function rules(): array
35
    {
36
        return [
37
            'name' => [
38
                'required',
39
                'min:5',
40
                Rule::unique('permissions')->ignore($this->permission)
41
            ],
42
            'description' => 'required|min:10',
43
        ];
44
    }
45
46
    /**
47
     * Function to store the model.
48
     *
49
     * @return Permission
50
     */
51
    public function create(): Permission
52
    {
53
        $properties = [
54
            'name',
55
            'description'
56
        ];
57
58
        return Permission::create($this->only($properties));
59
    }
60
61
    /**
62
     * Function to update the model.
63
     *
64
     * @return Permission
65
     */
66
    public function update(): Permission
67
    {
68
        $this->permission->update($this->only([
0 ignored issues
show
Bug introduced by
The method update() does not exist on null. ( Ignorable by Annotation )

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

68
        $this->permission->/** @scrutinizer ignore-call */ 
69
                           update($this->only([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
69
            'name',
70
            'description'
71
        ]));
72
73
        return $this->permission->fresh();
74
    }
75
}
76