DiscussCategoryForm   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 34
c 2
b 0
f 0
dl 0
loc 103
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 12 1
A rules() 0 13 1
A update() 0 12 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 Xetaravel\Models\DiscussCategory;
10
11
class DiscussCategoryForm extends Form
12
{
13
    /**
14
     * The category to update.
15
     *
16
     * @var DiscussCategory|null
17
     */
18
    public ?DiscussCategory $discussCategory = null;
19
20
    /**
21
     * The title of the category.
22
     *
23
     * @var string|null
24
     */
25
    public ?string $title = null;
26
27
    /**
28
     * The color of the category.
29
     *
30
     * @var string|null
31
     */
32
    public ?string $color = null;
33
34
    /**
35
     * The icon of the category.
36
     *
37
     * @var string|null
38
     */
39
    public ?string $icon = null;
40
41
    /**
42
     * The level of the category.
43
     *
44
     * @var int|null
45
     */
46
    public ?int $level = null;
47
48
    /**
49
     * Whatever the category is locked.
50
     *
51
     * @var bool|null
52
     */
53
    public ?bool $is_locked = false;
54
55
    /**
56
     * The description of the category.
57
     *
58
     * @var string|null
59
     */
60
    public ?string $description = null;
61
62
    protected function rules(): array
63
    {
64
        return [
65
            'title' => 'required|min:5',
66
            'color' => 'required|min:7|max:7|hex_color',
67
            'icon' => 'required|min:3',
68
            'level' => [
69
                'required',
70
                'int',
71
                Rule::unique('discuss_categories')->ignore($this->discussCategory)
72
            ],
73
            'is_locked' => 'required|bool',
74
            'description' => 'required|min:10',
75
        ];
76
    }
77
78
    /**
79
     * Function to store the model.
80
     *
81
     * @return DiscussCategory
82
     */
83
    public function create(): DiscussCategory
84
    {
85
        $properties = [
86
            'title',
87
            'color',
88
            'icon',
89
            'level',
90
            'is_locked',
91
            'description'
92
        ];
93
94
        return DiscussCategory::create($this->only($properties));
95
    }
96
97
    /**
98
     * Function to update the model.
99
     *
100
     * @return DiscussCategory
101
     */
102
    public function update(): DiscussCategory
103
    {
104
        $this->discussCategory->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

104
        $this->discussCategory->/** @scrutinizer ignore-call */ 
105
                                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...
105
            'title',
106
            'color',
107
            'icon',
108
            'level',
109
            'is_locked',
110
            'description'
111
        ]));
112
113
        return $this->discussCategory->fresh();
114
    }
115
}
116