CommentResource::table()   B
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 154
Code Lines 137

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 3
eloc 137
c 2
b 0
f 2
nc 1
nop 1
dl 0
loc 154
rs 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Filament\Resources;
4
5
use Filament\Actions\Action;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\Action was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Filament\Actions\BulkAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\BulkAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Filament\Actions\BulkActionGroup;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\BulkActionGroup was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Filament\Actions\DeleteAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\DeleteAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Filament\Actions\DeleteBulkAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\DeleteBulkAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Filament\Actions\EditAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\EditAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Filament\Actions\ForceDeleteBulkAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\ForceDeleteBulkAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Filament\Actions\RestoreAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\RestoreAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Filament\Actions\RestoreBulkAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\RestoreBulkAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Filament\Actions\ViewAction;
0 ignored issues
show
Bug introduced by
The type Filament\Actions\ViewAction was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Filament\Forms;
0 ignored issues
show
Bug introduced by
The type Filament\Forms was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Filament\Resources\Resource;
0 ignored issues
show
Bug introduced by
The type Filament\Resources\Resource was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Filament\Schemas\Schema;
0 ignored issues
show
Bug introduced by
The type Filament\Schemas\Schema was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Filament\Tables;
0 ignored issues
show
Bug introduced by
The type Filament\Tables was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Filament\Tables\Table;
0 ignored issues
show
Bug introduced by
The type Filament\Tables\Table was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Usamamuneerchaudhary\Commentify\Filament\Resources\CommentResource\Pages;
21
use Usamamuneerchaudhary\Commentify\Models\Comment;
22
23
class CommentResource extends Resource
24
{
25
    protected static ?string $model = Comment::class;
26
27
    protected static string|null|\BackedEnum $navigationIcon = 'heroicon-o-chat-bubble-left-right';
0 ignored issues
show
Bug introduced by
The type BackedEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
    protected static string|null|\UnitEnum $navigationGroup = 'Commentify';
0 ignored issues
show
Bug introduced by
The type UnitEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
31
    protected static ?int $navigationSort = 2;
32
33
    public static function form(Schema $schema): Schema
34
    {
35
        return $schema
36
            ->schema([
37
                Forms\Components\Select::make('user_id')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\Select was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
                    ->relationship('user', 'name')
39
                    ->searchable()
40
                    ->required()
41
                    ->disabled(),
42
                Forms\Components\Select::make('parent_id')
43
                    ->relationship('parent', 'id')
44
                    ->searchable()
45
                    ->nullable()
46
                    ->label('Parent Comment')
47
                    ->disabled(),
48
                Forms\Components\Textarea::make('body')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\Textarea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
                    ->required()
50
                    ->maxLength(5000)
51
                    ->rows(6)
52
                    ->columnSpanFull()
53
                    ->helperText('Supports Markdown formatting'),
54
                Forms\Components\Select::make('commentable_type')
55
                    ->label('Commentable Type')
56
                    ->options(function (Comment $record) {
57
                        if ($record->commentable_type) {
58
                            return [$record->commentable_type => class_basename($record->commentable_type)];
59
                        }
60
61
                        return [];
62
                    })
63
                    ->disabled(),
64
                Forms\Components\TextInput::make('commentable_id')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\TextInput was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
65
                    ->label('Commentable ID')
66
                    ->disabled(),
67
                Forms\Components\Toggle::make('is_approved')
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Components\Toggle was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
68
                    ->label('Approved')
69
                    ->default(false),
70
            ]);
71
    }
72
73
    public static function table(Table $table): Table
74
    {
75
        return $table
76
            ->modifyQueryUsing(function ($query) {
77
                return $query->withCount(['likes', 'children', 'reports']);
78
            })
79
            ->columns([
80
                Tables\Columns\TextColumn::make('id')
0 ignored issues
show
Bug introduced by
The type Filament\Tables\Columns\TextColumn was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
81
                    ->label('ID')
82
                    ->sortable()
83
                    ->searchable(),
84
                Tables\Columns\TextColumn::make('user.name')
85
                    ->label('User')
86
                    ->sortable()
87
                    ->searchable()
88
                    ->default('Unknown'),
89
                Tables\Columns\TextColumn::make('body')
90
                    ->label('Comment')
91
                    ->limit(50)
92
                    ->wrap()
93
                    ->searchable()
94
                    ->formatStateUsing(function (Comment $record) {
95
                        return strip_tags($record->presenter()->markdownBody());
96
                    }),
97
                Tables\Columns\TextColumn::make('commentable_type')
98
                    ->label('Type')
99
                    ->formatStateUsing(fn ($state) => $state ? class_basename($state) : '-')
100
                    ->sortable()
101
                    ->toggleable(),
102
                Tables\Columns\TextColumn::make('commentable_id')
103
                    ->label('Item ID')
104
                    ->sortable()
105
                    ->toggleable(),
106
                Tables\Columns\IconColumn::make('isParent')
0 ignored issues
show
Bug introduced by
The type Filament\Tables\Columns\IconColumn was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
107
                    ->label('Is Parent')
108
                    ->boolean()
109
                    ->getStateUsing(fn (Comment $record) => $record->isParent())
110
                    ->toggleable(),
111
                Tables\Columns\TextColumn::make('parent_id')
112
                    ->label('Parent ID')
113
                    ->sortable()
114
                    ->toggleable(isToggledHiddenByDefault: true),
115
                Tables\Columns\TextColumn::make('likes_count')
116
                    ->label('Likes')
117
                    ->sortable()
118
                    ->badge()
119
                    ->color('success')
120
                    ->default(0),
121
                Tables\Columns\TextColumn::make('children_count')
122
                    ->label('Replies')
123
                    ->sortable()
124
                    ->badge()
125
                    ->color('info')
126
                    ->default(0),
127
                Tables\Columns\TextColumn::make('reports_count')
128
                    ->label('Reports')
129
                    ->sortable()
130
                    ->badge()
131
                    ->color(fn ($state) => ($state ?? 0) > 0 ? 'danger' : 'gray')
132
                    ->default(0)
133
                    ->toggleable(),
134
                Tables\Columns\IconColumn::make('is_approved')
135
                    ->label('Approved')
136
                    ->boolean()
137
                    ->sortable()
138
                    ->toggleable(),
139
                Tables\Columns\TextColumn::make('created_at')
140
                    ->dateTime()
141
                    ->sortable()
142
                    ->toggleable(isToggledHiddenByDefault: true),
143
                Tables\Columns\TextColumn::make('updated_at')
144
                    ->dateTime()
145
                    ->sortable()
146
                    ->toggleable(isToggledHiddenByDefault: true),
147
                Tables\Columns\TextColumn::make('deleted_at')
148
                    ->dateTime()
149
                    ->sortable()
150
                    ->toggleable(isToggledHiddenByDefault: true)
151
                    ->label('Deleted At'),
152
            ])
153
            ->filters([
154
                Tables\Filters\SelectFilter::make('user_id')
0 ignored issues
show
Bug introduced by
The type Filament\Tables\Filters\SelectFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
155
                    ->relationship('user', 'name')
156
                    ->label('User')
157
                    ->searchable(),
158
                Tables\Filters\TernaryFilter::make('isParent')
0 ignored issues
show
Bug introduced by
The type Filament\Tables\Filters\TernaryFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
159
                    ->label('Parent Comments Only')
160
                    ->queries(
161
                        true: fn ($query) => $query->whereNull('parent_id'),
162
                        false: fn ($query) => $query->whereNotNull('parent_id'),
163
                    ),
164
                Tables\Filters\TernaryFilter::make('is_approved')
165
                    ->label('Approval Status')
166
                    ->placeholder('All Comments')
167
                    ->queries(
168
                        true: fn ($query) => $query->where('is_approved', true),
169
                        false: fn ($query) => $query->where('is_approved', false),
170
                    ),
171
                Tables\Filters\TrashedFilter::make(),
0 ignored issues
show
Bug introduced by
The type Filament\Tables\Filters\TrashedFilter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
172
            ])
173
            ->recordActions([
174
                ViewAction::make(),
175
                EditAction::make(),
176
                Action::make('approve')
177
                    ->label('Approve')
178
                    ->icon('heroicon-o-check-circle')
179
                    ->color('success')
180
                    ->requiresConfirmation()
181
                    ->visible(fn (Comment $record) => ! $record->is_approved)
182
                    ->action(function (Comment $record) {
183
                        $record->update(['is_approved' => true]);
184
                    }),
185
                Action::make('disapprove')
186
                    ->label('Disapprove')
187
                    ->icon('heroicon-o-x-circle')
188
                    ->color('danger')
189
                    ->requiresConfirmation()
190
                    ->visible(fn (Comment $record) => $record->is_approved)
191
                    ->action(function (Comment $record) {
192
                        $record->update(['is_approved' => false]);
193
                    }),
194
                DeleteAction::make(),
195
                RestoreAction::make(),
196
            ])
197
            ->toolbarActions([
198
                BulkActionGroup::make([
199
                    BulkAction::make('approve')
200
                        ->label('Approve Selected')
201
                        ->icon('heroicon-o-check-circle')
202
                        ->color('success')
203
                        ->requiresConfirmation()
204
                        ->action(function ($records) {
205
                            $records->each(function (Comment $record) {
206
                                $record->update(['is_approved' => true]);
207
                            });
208
                        })
209
                        ->deselectRecordsAfterCompletion(),
210
                    BulkAction::make('disapprove')
211
                        ->label('Disapprove Selected')
212
                        ->icon('heroicon-o-x-circle')
213
                        ->color('danger')
214
                        ->requiresConfirmation()
215
                        ->action(function ($records) {
216
                            $records->each(function (Comment $record) {
217
                                $record->update(['is_approved' => false]);
218
                            });
219
                        })
220
                        ->deselectRecordsAfterCompletion(),
221
                    DeleteBulkAction::make(),
222
                    RestoreBulkAction::make(),
223
                    ForceDeleteBulkAction::make(),
224
                ]),
225
            ])
226
            ->defaultSort('created_at', 'desc');
227
    }
228
229
    public static function getRelations(): array
230
    {
231
        return [
232
            CommentResource\RelationManagers\RepliesRelationManager::class,
233
            CommentResource\RelationManagers\ReportsRelationManager::class,
234
        ];
235
    }
236
237
    public static function getPages(): array
238
    {
239
        return [
240
            'index' => Pages\ListComments::route('/'),
241
            'create' => Pages\CreateComment::route('/create'),
242
            'view' => Pages\ViewComment::route('/{record}'),
243
            'edit' => Pages\EditComment::route('/{record}/edit'),
244
        ];
245
    }
246
}
247