Passed
Push — 5.0.0 ( 8a9c00...cfa35f )
by Fèvre
06:04
created

PermissionForm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 62
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 7 1
A create() 0 8 1
A rules() 0 9 1
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->name = $this->name;
69
        $this->permission->description = $this->description;
0 ignored issues
show
Bug introduced by
The property description does not seem to exist on Spatie\Permission\Models\Permission.
Loading history...
70
        $this->permission->save();
0 ignored issues
show
Bug introduced by
The method save() 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

70
        $this->permission->/** @scrutinizer ignore-call */ 
71
                           save();

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...
71
72
        return $this->permission;
73
    }
74
}
75