Passed
Push — main ( 4834b9...990a94 )
by Usama
03:51
created

CommentResource::form()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 33
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 29
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 33
rs 9.456
1
<?php
2
3
namespace Usamamuneerchaudhary\Commentify\Filament\Resources;
4
5
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...
6
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...
7
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...
8
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...
9
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...
10
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...
11
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...
12
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...
13
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...
14
use Filament\Forms\Form;
0 ignored issues
show
Bug introduced by
The type Filament\Forms\Form 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\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...
16
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...
17
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...
18
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...
19
use Usamamuneerchaudhary\Commentify\Filament\Resources\CommentResource\Pages;
20
use Usamamuneerchaudhary\Commentify\Models\Comment;
21
22
class CommentResource extends Resource
23
{
24
    protected static ?string $model = Comment::class;
25
26
    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...
27
28
    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...
29
30
    protected static ?int $navigationSort = 2;
31
32
    public static function form(Schema $schema): Schema
33
    {
34
        return $schema
35
            ->schema([
36
                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...
37
                    ->relationship('user', 'name')
38
                    ->searchable()
39
                    ->required()
40
                    ->disabled(),
41
                Forms\Components\Select::make('parent_id')
42
                    ->relationship('parent', 'id')
43
                    ->searchable()
44
                    ->nullable()
45
                    ->label('Parent Comment')
46
                    ->disabled(),
47
                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...
48
                    ->required()
49
                    ->maxLength(5000)
50
                    ->rows(6)
51
                    ->columnSpanFull()
52
                    ->helperText('Supports Markdown formatting'),
53
                Forms\Components\Select::make('commentable_type')
54
                    ->label('Commentable Type')
55
                    ->options(function (Comment $record) {
56
                        if ($record->commentable_type) {
57
                            return [$record->commentable_type => class_basename($record->commentable_type)];
58
                        }
59
                        return [];
60
                    })
61
                    ->disabled(),
62
                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...
63
                    ->label('Commentable ID')
64
                    ->disabled(),
65
            ]);
66
    }
67
68
    public static function table(Table $table): Table
69
    {
70
        return $table
71
            ->modifyQueryUsing(function ($query) {
72
                return $query->withCount(['likes', 'children', 'reports']);
73
            })
74
            ->columns([
75
                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...
76
                    ->label('ID')
77
                    ->sortable()
78
                    ->searchable(),
79
                Tables\Columns\TextColumn::make('user.name')
80
                    ->label('User')
81
                    ->sortable()
82
                    ->searchable()
83
                    ->default('Unknown'),
84
                Tables\Columns\TextColumn::make('body')
85
                    ->label('Comment')
86
                    ->limit(50)
87
                    ->wrap()
88
                    ->searchable()
89
                    ->formatStateUsing(function (Comment $record) {
90
                        return strip_tags($record->presenter()->markdownBody());
91
                    }),
92
                Tables\Columns\TextColumn::make('commentable_type')
93
                    ->label('Type')
94
                    ->formatStateUsing(fn ($state) => $state ? class_basename($state) : '-')
95
                    ->sortable()
96
                    ->toggleable(),
97
                Tables\Columns\TextColumn::make('commentable_id')
98
                    ->label('Item ID')
99
                    ->sortable()
100
                    ->toggleable(),
101
                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...
102
                    ->label('Is Parent')
103
                    ->boolean()
104
                    ->getStateUsing(fn (Comment $record) => $record->isParent())
105
                    ->toggleable(),
106
                Tables\Columns\TextColumn::make('parent_id')
107
                    ->label('Parent ID')
108
                    ->sortable()
109
                    ->toggleable(isToggledHiddenByDefault: true),
110
                Tables\Columns\TextColumn::make('likes_count')
111
                    ->label('Likes')
112
                    ->sortable()
113
                    ->badge()
114
                    ->color('success')
115
                    ->default(0),
116
                Tables\Columns\TextColumn::make('children_count')
117
                    ->label('Replies')
118
                    ->sortable()
119
                    ->badge()
120
                    ->color('info')
121
                    ->default(0),
122
                Tables\Columns\TextColumn::make('reports_count')
123
                    ->label('Reports')
124
                    ->sortable()
125
                    ->badge()
126
                    ->color(fn ($state) => ($state ?? 0) > 0 ? 'danger' : 'gray')
127
                    ->default(0)
128
                    ->toggleable(),
129
                Tables\Columns\TextColumn::make('created_at')
130
                    ->dateTime()
131
                    ->sortable()
132
                    ->toggleable(isToggledHiddenByDefault: true),
133
                Tables\Columns\TextColumn::make('updated_at')
134
                    ->dateTime()
135
                    ->sortable()
136
                    ->toggleable(isToggledHiddenByDefault: true),
137
                Tables\Columns\TextColumn::make('deleted_at')
138
                    ->dateTime()
139
                    ->sortable()
140
                    ->toggleable(isToggledHiddenByDefault: true)
141
                    ->label('Deleted At'),
142
            ])
143
            ->filters([
144
                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...
145
                    ->relationship('user', 'name')
146
                    ->label('User')
147
                    ->searchable(),
148
                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...
149
                    ->label('Parent Comments Only')
150
                    ->queries(
151
                        true: fn ($query) => $query->whereNull('parent_id'),
152
                        false: fn ($query) => $query->whereNotNull('parent_id'),
153
                    ),
154
                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...
155
            ])
156
            ->recordActions([
157
                ViewAction::make(),
158
                EditAction::make(),
159
                DeleteAction::make(),
160
                RestoreAction::make(),
161
            ])
162
            ->toolbarActions([
163
                BulkActionGroup::make([
164
                    DeleteBulkAction::make(),
165
                    RestoreBulkAction::make(),
166
                    ForceDeleteBulkAction::make(),
167
                ]),
168
            ])
169
            ->defaultSort('created_at', 'desc');
170
    }
171
172
    public static function getRelations(): array
173
    {
174
        return [
175
            CommentResource\RelationManagers\RepliesRelationManager::class,
176
            CommentResource\RelationManagers\ReportsRelationManager::class,
177
        ];
178
    }
179
180
    public static function getPages(): array
181
    {
182
        return [
183
            'index' => Pages\ListComments::route('/'),
184
            'create' => Pages\CreateComment::route('/create'),
185
            'view' => Pages\ViewComment::route('/{record}'),
186
            'edit' => Pages\EditComment::route('/{record}/edit'),
187
        ];
188
    }
189
}
190
191