Conditions | 2 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 41 |
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 |
||
164 | protected function getDefaultFunctions($object) |
||
165 | { |
||
166 | $functions = array(); |
||
167 | |||
168 | $functions[] = new \Twig_SimpleFunction('error', function ($key = null, $has_error = null, $no_error = '') use ($object) { |
||
169 | return $object->error($key, $has_error, $no_error); |
||
170 | }, array('is_safe' => array('all'))); |
||
171 | |||
172 | $functions[] = new \Twig_SimpleFunction('text', function ($text, $arguments = array()) use ($object) { |
||
173 | return $object->text($text, $arguments); |
||
174 | }, array('is_safe' => array('all'))); |
||
175 | |||
176 | $functions[] = new \Twig_SimpleFunction('access', function ($permission) use ($object) { |
||
177 | return $object->access($permission); |
||
178 | }); |
||
179 | |||
180 | $functions[] = new \Twig_SimpleFunction('url', function ($path = '', array $query = array(), $absolute = false) use ($object) { |
||
181 | return $object->url($path, $query, $absolute); |
||
182 | }); |
||
183 | |||
184 | $functions[] = new \Twig_SimpleFunction('isSuperadmin', function ($user_id = null) use ($object) { |
||
185 | return $object->isSuperadmin($user_id); |
||
186 | }); |
||
187 | |||
188 | $functions[] = new \Twig_SimpleFunction('date', function ($timestamp = null, $full = true, $unix_format = '') use ($object) { |
||
189 | return $object->date($timestamp, $full, $unix_format); |
||
190 | }); |
||
191 | |||
192 | $functions[] = new \Twig_SimpleFunction('attributes', function ($attributes) use ($object) { |
||
193 | return $object->attributes($attributes); |
||
194 | }, array('is_safe' => array('all'))); |
||
195 | |||
196 | $functions[] = new \Twig_SimpleFunction('config', function ($key = null, $default = null) use ($object) { |
||
197 | return $object->config($key, $default); |
||
198 | }); |
||
199 | |||
200 | $functions[] = new \Twig_SimpleFunction('settings', function ($key = null, $default = null) use ($object) { |
||
201 | return $object->settings($key, $default); |
||
202 | }); |
||
203 | |||
204 | $functions[] = new \Twig_SimpleFunction('summary', function ($text, $xss = false, $filter = null) use ($object) { |
||
205 | return $object->summary($text, $xss, $filter); |
||
206 | }, array('is_safe' => array('all'))); |
||
207 | |||
208 | $functions[] = new \Twig_SimpleFunction('d', function ($key = null) use ($object) { |
||
209 | if (function_exists('d')) { |
||
210 | d($object->getData($key)); // Kint |
||
211 | } else { |
||
212 | print_r($object->getData($key), true); |
||
213 | } |
||
214 | }); |
||
215 | |||
216 | $functions[] = new \Twig_SimpleFunction('filter', function ($text, $filter = null) use ($object) { |
||
217 | return $object->filter($text, $filter); |
||
218 | }, array('is_safe' => array('all'))); |
||
219 | |||
220 | $functions[] = new \Twig_SimpleFunction('truncate', function ($string, $length = 100, $trimmarker = '...') use ($object) { |
||
221 | return $object->truncate($string, $length, $trimmarker); |
||
222 | }); |
||
223 | |||
224 | $functions[] = new \Twig_SimpleFunction('prop', function ($name) use ($object) { |
||
225 | return $object->prop($name); |
||
226 | }); |
||
227 | |||
228 | $functions[] = new \Twig_SimpleFunction('path', function ($path = null) use ($object) { |
||
229 | return $object->path($path); |
||
230 | }); |
||
231 | |||
232 | return $functions; |
||
233 | } |
||
234 | |||
268 |