Conditions | 6 |
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 |
||
82 | public function columns(): array |
||
83 | { |
||
84 | return [ |
||
85 | Column::make('ID', 'id') |
||
86 | ->sortable() |
||
87 | ->searchable(), |
||
88 | Column::make('Name', 'name') |
||
89 | ->sortable() |
||
90 | ->searchable(), |
||
91 | Column::make('Category', 'category_id') |
||
92 | ->format( |
||
93 | fn ($value, $row, Column $column) => $row->category->name ?? '-' |
||
94 | ) |
||
95 | ->sortable() |
||
96 | ->searchable() |
||
97 | ->collapseOnTablet(), |
||
98 | Column::make('Active', 'active') |
||
99 | ->format( |
||
100 | fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('active') ? 'success' : 'danger').' ">'.($row->getRawOriginal('active') ? 'Active' : 'Inactive').'</span>' |
||
101 | ) |
||
102 | ->html() |
||
103 | ->collapseOnTablet(), |
||
104 | Column::make('Popup', 'popup') |
||
105 | ->format( |
||
106 | fn ($value, $row, Column $column) => '<span class="badge badge-'.($row->getRawOriginal('popup') ? 'success' : 'primary').' ">'.($row->getRawOriginal('popup') ? 'Popup' : 'No Popup').'</span>' |
||
107 | ) |
||
108 | ->html() |
||
109 | ->collapseOnTablet(), |
||
110 | Column::make('Icon', 'icon') |
||
111 | ->format( |
||
112 | fn ($value, $row, Column $column) => '<span class="'.$row->icon.' "></span>' |
||
113 | ) |
||
114 | ->html() |
||
115 | ->collapseOnTablet(), |
||
116 | Column::make('Color', 'color') |
||
117 | ->format( |
||
118 | fn ($value, $row, Column $column) => '<span style="height:30px;width:50px;background-color:'.$row->color.'"></span>' |
||
119 | ) |
||
120 | ->html() |
||
121 | ->collapseOnTablet(), |
||
122 | Column::make('Expiry', 'expire') |
||
123 | ->format( |
||
124 | fn ($value, $row, Column $column) => ! is_null($row->expire) ? (Carbon::create($row->expire))->toFormattedDayDateString() : '' |
||
125 | ) |
||
126 | ->html() |
||
127 | ->collapseOnTablet(), |
||
128 | Column::make('Action') |
||
129 | ->label( |
||
130 | fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="popup" />', ['model' => $row]) |
||
131 | ) |
||
132 | ->html() |
||
133 | ->collapseOnTablet(), |
||
134 | ]; |
||
137 |