| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 21 | public function buildGrid() |
||
| 22 | { |
||
| 23 | $booleanOptions = [self::YES => 'Tak', self::NO => 'Nie']; |
||
| 24 | |||
| 25 | $this |
||
| 26 | ->setDefaultOrder(new Order('id', 'desc')) |
||
| 27 | ->addColumn('id', [ |
||
| 28 | 'title' => 'ID', |
||
| 29 | 'sortable' => true |
||
| 30 | ]) |
||
| 31 | ->addColumn('name', [ |
||
| 32 | 'title' => 'Nazwa użytkownika', |
||
| 33 | 'sortable' => true, |
||
| 34 | 'clickable' => function (User $user) { |
||
| 35 | return link_to_route('adm.users.save', $user->name, [$user->id]); |
||
| 36 | }, |
||
| 37 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
||
| 38 | ]) |
||
| 39 | ->addColumn('email', [ |
||
| 40 | 'title' => 'E-mail', |
||
| 41 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
||
| 42 | ]) |
||
| 43 | ->addColumn('created_at', [ |
||
| 44 | 'title' => 'Data rejestracji' |
||
| 45 | ]) |
||
| 46 | ->addColumn('visited_at', [ |
||
| 47 | 'title' => 'Data ost. wizyty', |
||
| 48 | 'sortable' => true |
||
| 49 | ]) |
||
| 50 | ->addColumn('is_active', [ |
||
| 51 | 'title' => 'Aktywny', |
||
| 52 | 'decorators' => [new Boolean()], |
||
| 53 | 'filter' => new Select(['options' => $booleanOptions]) |
||
| 54 | ]) |
||
| 55 | ->addColumn('is_blocked', [ |
||
| 56 | 'title' => 'Zablokowany', |
||
| 57 | 'decorators' => [new Boolean()], |
||
| 58 | 'filter' => new Select(['options' => $booleanOptions]) |
||
| 59 | ]) |
||
| 60 | ->addColumn('ip', [ |
||
| 61 | 'title' => 'IP', |
||
| 62 | 'decorators' => [new Ip()], |
||
| 63 | 'filter' => new Text(['operator' => FilterOperator::OPERATOR_ILIKE]) |
||
| 64 | ]) |
||
| 65 | ->addColumn('reputation', [ |
||
| 66 | 'title' => 'Reputacja', |
||
| 67 | 'sortable' => true |
||
| 68 | ]) |
||
| 69 | ->addRowAction(new FirewallButton(function (User $user) { |
||
| 70 | return route('adm.firewall.save') . '?' . http_build_query(['user' => $user->id, 'ip' => $user->ip]); |
||
| 71 | })) |
||
| 72 | ->addRowAction(new EditButton(function (User $user) { |
||
| 73 | return route('adm.users.save', [$user->id]); |
||
| 74 | })); |
||
| 75 | } |
||
| 76 | } |
||
| 77 |