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

BlogCategoryForm::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
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\Attributes\Validate;
9
use Livewire\Form;
10
use Xetaravel\Models\BlogCategory;
11
12
class BlogCategoryForm extends Form
13
{
14
    /**
15
     * The category to update.
16
     *
17
     * @var BlogCategory|null
18
     */
19
    public ?BlogCategory $blogCategory = null;
20
21
    /**
22
     * The title of the category.
23
     *
24
     * @var string|null
25
     */
26
    public ?string $title = null;
27
28
    /**
29
     * The description of the category.
30
     *
31
     * @var string|null
32
     */
33
    public ?string $description = null;
34
35
    protected function rules(): array
36
    {
37
        return [
38
            'title' => [
39
                'required',
40
                'min:5',
41
                Rule::unique('blog_categories')->ignore($this->blogCategory)
42
            ],
43
            'description' => 'required|min:10',
44
        ];
45
    }
46
47
    /**
48
     * Function to store the model.
49
     *
50
     * @return BlogCategory
51
     */
52
    public function create(): BlogCategory
53
    {
54
        $properties = [
55
            'title',
56
            'description'
57
        ];
58
59
        return BlogCategory::create($this->only($properties));
60
    }
61
62
    /**
63
     * Function to update the model.
64
     *
65
     * @return BlogCategory
66
     */
67
    public function update(): BlogCategory
68
    {
69
        $this->blogCategory->title = $this->title;
70
        $this->blogCategory->description = $this->description;
71
        $this->blogCategory->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

71
        $this->blogCategory->/** @scrutinizer ignore-call */ 
72
                             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...
72
73
        return $this->blogCategory;
74
    }
75
}
76