Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 37 |
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 |
||
52 | public function setupListOperation() |
||
53 | { |
||
54 | CRUD::setColumns([ |
||
55 | [ |
||
56 | // Commentable entity |
||
57 | 'label' => 'Commentable', |
||
58 | 'type' => 'select', |
||
59 | 'name' => 'commentable_id', |
||
60 | 'entity' => 'commentable', |
||
61 | 'attribute' => 'name', |
||
62 | ], |
||
63 | |||
64 | [ |
||
65 | // Commentable entity |
||
66 | 'label' => 'Commentable', |
||
67 | 'type' => 'text', |
||
68 | 'name' => 'body', |
||
69 | ], |
||
70 | |||
71 | [ |
||
72 | // Commentable entity |
||
73 | 'label' => 'Author', |
||
74 | 'type' => 'select', |
||
75 | 'name' => 'author_id', |
||
76 | 'entity' => 'author', |
||
77 | 'attribute' => 'name', |
||
78 | ], |
||
79 | |||
80 | [ |
||
81 | // Commentable entity |
||
82 | 'label' => 'Action', |
||
83 | 'type' => 'boolean', |
||
84 | 'name' => 'action', |
||
85 | ], |
||
86 | ]); |
||
87 | |||
88 | CRUD::addFilter( |
||
89 | [ // simple filter |
||
90 | 'type' => 'simple', |
||
91 | 'name' => 'action', |
||
92 | 'label' => 'Action', |
||
93 | ], |
||
94 | false, |
||
95 | function () { |
||
96 | CRUD::addClause('where', 'action', true); |
||
97 | } |
||
98 | ); |
||
99 | |||
100 | CRUD::addFilter( |
||
101 | [ // dropdown filter |
||
102 | 'name' => 'type', |
||
103 | 'type' => 'dropdown', |
||
104 | 'label' => 'Type', |
||
105 | ], |
||
106 | [ |
||
107 | Student::class => 'Student', |
||
108 | Enrollment::class => 'Enrollments', |
||
109 | Invoice::class => 'Invoice', |
||
110 | Result::class => 'Result', |
||
111 | |||
112 | ], |
||
113 | function ($value) { |
||
114 | CRUD::addClause('where', 'commentable_type', '=', $value); |
||
115 | }, |
||
116 | function () { // if the filter is not active |
||
117 | CRUD::addClause('where', 'commentable_type', '=', Student::class); |
||
118 | $this->crud->getRequest()->request->add(['commentable_type' => Student::class]); // to make the filter look active |
||
119 | } |
||
137 |