Passed
Push — 5.0.0 ( dd8bc0...b0cec2 )
by Fèvre
05:00
created

Comment   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 76
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRowsQueryProperty() 0 7 1
A mount() 0 3 1
A getRowsProperty() 0 4 1
A render() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Livewire\Blog;
6
7
use Illuminate\Contracts\Database\Query\Builder;
8
use Illuminate\Contracts\View\View;
9
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
10
use Illuminate\Pagination\LengthAwarePaginator;
11
use Livewire\Component;
12
use Xetaravel\Livewire\Traits\WithCachedRows;
13
use Xetaravel\Livewire\Traits\WithPerPagePagination;
14
use Xetaravel\Livewire\Traits\WithSorting;
15
use Xetaravel\Models\BlogArticle;
16
use Xetaravel\Models\BlogComment;
17
18
class Comment extends Component
19
{
20
    use AuthorizesRequests;
21
    use WithCachedRows;
22
    use WithPerPagePagination;
23
    use WithSorting;
24
25
    public BlogArticle $article;
26
27
    /**
28
     * Number of rows displayed on a page.
29
     *
30
     * @var int
31
     */
32
    public int $perPage = 25;
33
34
    /**
35
     * The field to sort by.
36
     *
37
     * @var string
38
     */
39
    public string $sortField = 'created_at';
40
41
    /**
42
     * The direction of the ordering.
43
     *
44
     * @var string
45
     */
46
    public string $sortDirection = 'desc';
47
48
    /**
49
     * Array of allowed fields.
50
     *
51
     * @var array
52
     */
53
    public array $allowedFields = [
54
        'created_at'
55
    ];
56
57
    public $content;
58
59
    public function mount(BlogArticle $article): void
60
    {
61
        $this->article = $article;
62
    }
63
64
    public function render(): View
65
    {
66
        return view('livewire.blog.comment', [
67
            'comments' => $this->rows
0 ignored issues
show
Bug Best Practice introduced by
The property rows does not exist on Xetaravel\Livewire\Blog\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
68
        ]);
69
    }
70
71
    /**
72
     * Create and return the query for the items.
73
     *
74
     * @return Builder
75
     */
76
    public function getRowsQueryProperty(): Builder
77
    {
78
        $query = BlogComment::query()
79
            ->with('user', )
80
            ->where('blog_article_id', $this->article->id);
81
82
        return $this->applySorting($query);
83
    }
84
85
    /**
86
     * Build the query or get it from the cache and paginate it.
87
     *
88
     * @return LengthAwarePaginator
89
     */
90
    public function getRowsProperty(): LengthAwarePaginator
91
    {
92
        return $this->cache(function () {
93
            return $this->applyPagination($this->rowsQuery);
0 ignored issues
show
Bug Best Practice introduced by
The property rowsQuery does not exist on Xetaravel\Livewire\Blog\Comment. Since you implemented __get, consider adding a @property annotation.
Loading history...
94
        });
95
    }
96
}
97