| Conditions | 3 |
| Paths | 1 |
| Total Lines | 102 |
| Code Lines | 92 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 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') |
||
| 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') |
||
| 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') |
||
| 145 | ->relationship('user', 'name') |
||
| 146 | ->label('User') |
||
| 147 | ->searchable(), |
||
| 148 | Tables\Filters\TernaryFilter::make('isParent') |
||
| 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(), |
||
| 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 | } |
||
| 191 |
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