| Conditions | 2 |
| Paths | 1 |
| Total Lines | 94 |
| Code Lines | 54 |
| 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('user', function ($item = null) use ($object) { |
||
| 209 | return $object->user($item); |
||
| 210 | }); |
||
| 211 | |||
| 212 | $functions[] = new \Twig_SimpleFunction('store', function ($item = null) use ($object) { |
||
| 213 | return $object->store($item); |
||
| 214 | }); |
||
| 215 | |||
| 216 | $functions[] = new \Twig_SimpleFunction('d', function ($key = null) use ($object) { |
||
| 217 | if (function_exists('d')) { |
||
| 218 | d($object->getData($key)); // Kint |
||
| 219 | } else { |
||
| 220 | print_r($object->getData($key), true); |
||
| 221 | } |
||
| 222 | }); |
||
| 223 | |||
| 224 | $functions[] = new \Twig_SimpleFunction('filter', function ($text, $filter = null) use ($object) { |
||
| 225 | return $object->filter($text, $filter); |
||
| 226 | }, array('is_safe' => array('all'))); |
||
| 227 | |||
| 228 | $functions[] = new \Twig_SimpleFunction('truncate', function ($string, $length = 100, $trimmarker = '...') use ($object) { |
||
| 229 | return $object->truncate($string, $length, $trimmarker); |
||
| 230 | }); |
||
| 231 | |||
| 232 | $functions[] = new \Twig_SimpleFunction('cart', function ($key = null) use ($object) { |
||
| 233 | return $object->cart($key); |
||
| 234 | }); |
||
| 235 | |||
| 236 | $functions[] = new \Twig_SimpleFunction('compare', function ($key = null) use ($object) { |
||
| 237 | return $object->compare($key); |
||
| 238 | }); |
||
| 239 | |||
| 240 | $functions[] = new \Twig_SimpleFunction('wishlist', function ($key = null) use ($object) { |
||
| 241 | return $object->wishlist($key); |
||
| 242 | }); |
||
| 243 | |||
| 244 | $functions[] = new \Twig_SimpleFunction('menu', function (array $options = array()) use ($object) { |
||
| 245 | return $object->menu($options); |
||
| 246 | }, array('is_safe' => array('all'))); |
||
| 247 | |||
| 248 | $functions[] = new \Twig_SimpleFunction('prop', function ($name) use ($object) { |
||
| 249 | return $object->prop($name); |
||
| 250 | }); |
||
| 251 | |||
| 252 | $functions[] = new \Twig_SimpleFunction('path', function ($path = null) use ($object) { |
||
| 253 | return $object->path($path); |
||
| 254 | }); |
||
| 255 | |||
| 256 | return $functions; |
||
| 257 | } |
||
| 258 | |||
| 292 |