Passed
Push — 5.0.0 ( 757365...6c4e14 )
by Fèvre
05:11
created

BlogCategoryForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A update() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Forms;
6
7
use Livewire\Attributes\Validate;
8
use Livewire\Form;
9
use Xetaravel\Models\BlogCategory;
10
11
class BlogCategoryForm extends Form
12
{
13
    /**
14
     * The category to update.
15
     *
16
     * @var BlogCategory|null
17
     */
18
    public ?BlogCategory $blogCategory = null;
19
20
    /**
21
     * The title of the category.
22
     *
23
     * @var string|null
24
     */
25
    #[Validate('required|min:5')]
26
    public ?string $title = null;
27
28
    /**
29
     * The description of the category.
30
     *
31
     * @var string|null
32
     */
33
    #[Validate('required|min:10')]
34
    public ?string $description = null;
35
36
    /**
37
     * Function to store the model.
38
     *
39
     * @return BlogCategory
40
     */
41
    public function create(): BlogCategory
42
    {
43
        $properties = [
44
            'title',
45
            'description'
46
        ];
47
48
        return BlogCategory::create($this->only($properties));
49
    }
50
51
    /**
52
     * Function to update the model.
53
     *
54
     * @return BlogCategory
55
     */
56
    public function update(): BlogCategory
57
    {
58
        $this->blogCategory->title = $this->title;
59
        $this->blogCategory->description = $this->description;
60
        $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

60
        $this->blogCategory->/** @scrutinizer ignore-call */ 
61
                             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...
61
62
        return $this->blogCategory;
63
    }
64
}
65