| Conditions | 5 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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 |
||
| 121 | public function columns(): array |
||
| 122 | { |
||
| 123 | return [ |
||
| 124 | Column::make('ID', 'id') |
||
| 125 | ->sortable() |
||
| 126 | ->searchable(), |
||
| 127 | Column::make('Name', 'name') |
||
| 128 | ->sortable() |
||
| 129 | ->searchable(), |
||
| 130 | Column::make('Category', 'category_id') |
||
| 131 | ->format( |
||
| 132 | fn ($value, $row, Column $column) => $row->category->name ?? '-' |
||
| 133 | ) |
||
| 134 | ->sortable() |
||
| 135 | ->searchable() |
||
| 136 | ->collapseOnTablet(), |
||
| 137 | Column::make('Active', 'active') |
||
| 138 | ->format( |
||
| 139 | fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('active') ? 'success' : 'danger').' ">'.($row->getRawOriginal('active') ? 'Active' : 'Inactive').'</span>' |
||
| 140 | ) |
||
| 141 | ->html() |
||
| 142 | ->collapseOnTablet(), |
||
| 143 | Column::make('Featured', 'featured') |
||
| 144 | ->format( |
||
| 145 | fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('featured') ? 'success' : 'primary').' ">'.($row->getRawOriginal('featured') ? 'Featured' : 'Not Featured').'</span>' |
||
| 146 | ) |
||
| 147 | ->html() |
||
| 148 | ->collapseOnTablet(), |
||
| 149 | Column::make('Status', 'status') |
||
| 150 | ->format( |
||
| 151 | fn ($value, $row, Column $column) => '<span class="badge badge-info">'.$row->status.'</span>' |
||
| 152 | ) |
||
| 153 | ->html() |
||
| 154 | ->collapseOnTablet(), |
||
| 155 | Column::make('Icon', 'icon') |
||
| 156 | ->format( |
||
| 157 | fn ($value, $row, Column $column) => '<span class="'.$row->icon.' "></span>' |
||
| 158 | ) |
||
| 159 | ->html() |
||
| 160 | ->collapseOnTablet(), |
||
| 161 | Column::make('Color', 'color') |
||
| 162 | ->format( |
||
| 163 | fn ($value, $row, Column $column) => '<span style="height:30px;width:50px;background-color:'.$row->color.'"></span>' |
||
| 164 | ) |
||
| 165 | ->html() |
||
| 166 | ->collapseOnTablet(), |
||
| 167 | Column::make('Action') |
||
| 168 | ->label( |
||
| 169 | fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="project" />', ['model' => $row]) |
||
| 170 | ) |
||
| 171 | ->html() |
||
| 172 | ->collapseOnTablet(), |
||
| 173 | ]; |
||
| 176 |