UpdateCategory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A update() 0 11 1
A updateCategory() 0 13 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Admin\Blog;
6
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Foundation\Application;
10
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
11
use Livewire\Attributes\On;
12
use Livewire\Component;
13
use Masmerise\Toaster\Toastable;
14
use Xetaravel\Livewire\Forms\BlogCategoryForm;
15
use Xetaravel\Models\BlogCategory;
16
17
class UpdateCategory extends Component
18
{
19
    use AuthorizesRequests;
20
    use Toastable;
21
22
    /**
23
     * The form used to create/update a model.
24
     *
25
     * @var BlogCategoryForm
26
     */
27
    public BlogCategoryForm $form;
28
29
    /**
30
     * Used to show the update modal.
31
     *
32
     * @var bool
33
     */
34
    public bool $showModal = false;
35
36
    public function render(): View|Application|Factory|\Illuminate\View\View
37
    {
38
        return view('livewire.admin.blog.update-category');
39
    }
40
41
    /**
42
     * When a user click on 'Edit' open the modal and set the content.
43
     *
44
     * @param BlogCategory $blogCategory
45
     *
46
     * @return void
47
     */
48
    #[On('update-category')]
49
    public function updateCategory(BlogCategory $blogCategory): void
50
    {
51
        $this->authorize('update', $blogCategory);
52
53
        $this->form->reset();
54
        $this->form->fill([
55
            'blogCategory' => $blogCategory,
56
            'title' => $blogCategory->title,
57
            'description' => $blogCategory->description,
58
        ]);
59
60
        $this->showModal = true;
61
    }
62
63
    /**
64
     * Update the category.
65
     *
66
     * @return void
67
     */
68
    public function update(): void
69
    {
70
        $this->authorize('update', $this->form->blogCategory);
71
72
        $this->validate();
73
74
        $this->form->update();
75
76
        redirect()
77
            ->route('admin.blog.category.index')
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

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

77
            ->/** @scrutinizer ignore-call */ route('admin.blog.category.index')

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...
78
            ->success('Your category has been updated successfully !');
79
    }
80
}
81