| Conditions | 3 |
| Paths | 1 |
| Total Lines | 154 |
| Code Lines | 137 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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') |
||
| 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') |
||
| 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') |
||
| 155 | ->relationship('user', 'name') |
||
| 156 | ->label('User') |
||
| 157 | ->searchable(), |
||
| 158 | Tables\Filters\TernaryFilter::make('isParent') |
||
| 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(), |
||
| 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 | } |
||
| 247 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths