| Conditions | 4 |
| Paths | 1 |
| Total Lines | 215 |
| Code Lines | 144 |
| Lines | 18 |
| Ratio | 8.37 % |
| 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 namespace Anomaly\Streams\Platform; |
||
| 173 | public function getFunctions() |
||
| 174 | { |
||
| 175 | return [ |
||
| 176 | new \Twig_SimpleFunction( |
||
| 177 | 'entry', |
||
| 178 | function ($namespace, $stream = null) { |
||
| 179 | return (new Decorator())->decorate( |
||
| 180 | $this->dispatch(new GetEntryCriteria($namespace, $stream ?: $namespace, 'first')) |
||
| 181 | ); |
||
| 182 | } |
||
| 183 | ), |
||
| 184 | new \Twig_SimpleFunction( |
||
| 185 | 'entries', |
||
| 186 | function ($namespace, $stream = null) { |
||
| 187 | return (new Decorator())->decorate( |
||
| 188 | $this->dispatch(new GetEntryCriteria($namespace, $stream ?: $namespace, 'get')) |
||
| 189 | ); |
||
| 190 | } |
||
| 191 | ), |
||
| 192 | new \Twig_SimpleFunction( |
||
| 193 | 'image_path', |
||
| 194 | function ($image) { |
||
| 195 | return $this->dispatch(new MakeImagePath($image)); |
||
| 196 | } |
||
| 197 | ), |
||
| 198 | new \Twig_SimpleFunction( |
||
| 199 | 'image_url', |
||
| 200 | function ($image) { |
||
| 201 | return $this->dispatch(new MakeImageUrl($image)); |
||
| 202 | } |
||
| 203 | ), |
||
| 204 | new \Twig_SimpleFunction( |
||
| 205 | 'image', |
||
| 206 | function ($image) { |
||
| 207 | return $this->dispatch(new MakeImageTag($image)); |
||
| 208 | }, |
||
| 209 | [ |
||
| 210 | 'is_safe' => ['html'] |
||
| 211 | ] |
||
| 212 | ), |
||
| 213 | new \Twig_SimpleFunction( |
||
| 214 | 'img', |
||
| 215 | function ($image) { |
||
| 216 | return $this->dispatch(new MakeImageTag($image)); |
||
| 217 | }, |
||
| 218 | [ |
||
| 219 | 'is_safe' => ['html'] |
||
| 220 | ] |
||
| 221 | ), |
||
| 222 | new \Twig_SimpleFunction( |
||
| 223 | 'form', |
||
| 224 | function ($parameters) { |
||
| 225 | return $this->dispatch(new GetFormCriteria($parameters)); |
||
| 226 | }, |
||
| 227 | [ |
||
| 228 | 'is_safe' => ['html'] |
||
| 229 | ] |
||
| 230 | ), |
||
| 231 | new \Twig_SimpleFunction( |
||
| 232 | 'icon', |
||
| 233 | function ($type, $class = null) { |
||
| 234 | return (new Decorator())->decorate($this->dispatch(new GetIcon($type, $class))); |
||
| 235 | }, |
||
| 236 | [ |
||
| 237 | 'is_safe' => ['html'] |
||
| 238 | ] |
||
| 239 | ), |
||
| 240 | new \Twig_SimpleFunction( |
||
| 241 | 'view', |
||
| 242 | function ($view, array $data = []) { |
||
| 243 | return $this->dispatch(new GetView($view, $data))->render(); |
||
| 244 | }, |
||
| 245 | [ |
||
| 246 | 'is_safe' => ['html'] |
||
| 247 | ] |
||
| 248 | ), |
||
| 249 | new \Twig_SimpleFunction( |
||
| 250 | 'buttons', |
||
| 251 | function ($buttons) { |
||
| 252 | return $this->dispatch(new GetButtons($buttons))->render(); |
||
| 253 | }, |
||
| 254 | [ |
||
| 255 | 'is_safe' => ['html'] |
||
| 256 | ] |
||
| 257 | ), |
||
| 258 | new \Twig_SimpleFunction( |
||
| 259 | 'constants', |
||
| 260 | function () { |
||
| 261 | return $this->dispatch(new GetConstants())->render(); |
||
| 262 | }, |
||
| 263 | [ |
||
| 264 | 'is_safe' => ['html'] |
||
| 265 | ] |
||
| 266 | ), |
||
| 267 | new \Twig_SimpleFunction( |
||
| 268 | 'env', |
||
| 269 | function ($key, $default = null) { |
||
| 270 | return env($key, $default); |
||
| 271 | } |
||
| 272 | ), |
||
| 273 | new \Twig_SimpleFunction( |
||
| 274 | 'decorate', |
||
| 275 | function ($value) { |
||
| 276 | return (new Decorator())->decorate($value); |
||
| 277 | } |
||
| 278 | ), |
||
| 279 | new \Twig_SimpleFunction( |
||
| 280 | 'request_time', |
||
| 281 | function ($decimal = 2) { |
||
| 282 | return $this->dispatch(new GetElapsedTime($decimal)); |
||
| 283 | } |
||
| 284 | ), |
||
| 285 | new \Twig_SimpleFunction( |
||
| 286 | 'memory_usage', |
||
| 287 | function ($precision = 1) { |
||
| 288 | return $this->dispatch(new GetMemoryUsage($precision)); |
||
| 289 | } |
||
| 290 | ), |
||
| 291 | new \Twig_SimpleFunction( |
||
| 292 | 'layout', |
||
| 293 | function ($layout, $default = 'default') { |
||
| 294 | return $this->dispatch(new GetLayoutName($layout, $default)); |
||
| 295 | } |
||
| 296 | ), |
||
| 297 | new \Twig_SimpleFunction( |
||
| 298 | 'request_*', |
||
| 299 | View Code Duplication | function ($name) { |
|
| 300 | |||
| 301 | $arguments = array_slice(func_get_args(), 1); |
||
| 302 | |||
| 303 | return call_user_func_array([$this->request, camel_case($name)], $arguments); |
||
| 304 | } |
||
| 305 | ), |
||
| 306 | new \Twig_SimpleFunction( |
||
| 307 | 'trans', |
||
| 308 | function ($key, array $parameters = [], $locale = 'en') { |
||
| 309 | return $this->dispatch(new GetTranslatedString($key, $parameters, $locale)); |
||
| 310 | } |
||
| 311 | ), |
||
| 312 | new \Twig_SimpleFunction( |
||
| 313 | 'str_*', |
||
| 314 | View Code Duplication | function ($name) { |
|
| 315 | |||
| 316 | $arguments = array_slice(func_get_args(), 1); |
||
| 317 | |||
| 318 | return call_user_func_array([$this->str, camel_case($name)], $arguments); |
||
| 319 | } |
||
| 320 | ), |
||
| 321 | new \Twig_SimpleFunction( |
||
| 322 | 'url_*', |
||
| 323 | View Code Duplication | function ($name) { |
|
| 324 | |||
| 325 | $arguments = array_slice(func_get_args(), 1); |
||
| 326 | |||
| 327 | return call_user_func_array([$this->url, camel_case($name)], $arguments); |
||
| 328 | } |
||
| 329 | ), |
||
| 330 | new \Twig_SimpleFunction( |
||
| 331 | 'addons', |
||
| 332 | function ($type = null) { |
||
| 333 | |||
| 334 | $addons = app(AddonCollection::class); |
||
| 335 | |||
| 336 | if ($type) { |
||
| 337 | $addons = $addons->{str_plural($type)}(); |
||
| 338 | } |
||
| 339 | |||
| 340 | return $addons; |
||
| 341 | } |
||
| 342 | ), |
||
| 343 | new \Twig_SimpleFunction('input_get', [$this->request, 'input']), |
||
| 344 | new \Twig_SimpleFunction('asset', [$this->url, 'asset'], ['is_safe' => ['html']]), |
||
| 345 | new \Twig_SimpleFunction('action', [$this->url, 'action'], ['is_safe' => ['html']]), |
||
| 346 | new \Twig_SimpleFunction('url', [$this, 'url'], ['is_safe' => ['html']]), |
||
| 347 | new \Twig_SimpleFunction('route', [$this->url, 'route'], ['is_safe' => ['html']]), |
||
| 348 | new \Twig_SimpleFunction('route_has', [$this->router, 'has'], ['is_safe' => ['html']]), |
||
| 349 | new \Twig_SimpleFunction('secure_url', [$this->url, 'secure'], ['is_safe' => ['html']]), |
||
| 350 | new \Twig_SimpleFunction('secure_asset', [$this->url, 'secureAsset'], ['is_safe' => ['html']]), |
||
| 351 | new \Twig_SimpleFunction('config', [$this->config, 'get']), |
||
| 352 | new \Twig_SimpleFunction('config_get', [$this->config, 'get']), |
||
| 353 | new \Twig_SimpleFunction('config_has', [$this->config, 'has']), |
||
| 354 | new \Twig_SimpleFunction('auth_user', [$this->auth, 'user']), |
||
| 355 | new \Twig_SimpleFunction('auth_check', [$this->auth, 'check']), |
||
| 356 | new \Twig_SimpleFunction('auth_guest', [$this->auth, 'guest']), |
||
| 357 | new \Twig_SimpleFunction('trans_exists', [$this->translator, 'exists']), |
||
| 358 | new \Twig_SimpleFunction('message_get', [$this->session, 'pull']), |
||
| 359 | new \Twig_SimpleFunction('message_exists', [$this->session, 'has']), |
||
| 360 | new \Twig_SimpleFunction('session', [$this->session, 'get']), |
||
| 361 | new \Twig_SimpleFunction('parse', [$this->template, 'render'], ['is_safe' => ['html']]), |
||
| 362 | new \Twig_SimpleFunction('csrf_token', [$this->session, 'token'], ['is_safe' => ['html']]), |
||
| 363 | new \Twig_SimpleFunction('csrf_field', 'csrf_field', ['is_safe' => ['html']]), |
||
| 364 | new \Twig_SimpleFunction('session_get', [$this->session, 'get']), |
||
| 365 | new \Twig_SimpleFunction('session_pull', [$this->session, 'pull']), |
||
| 366 | new \Twig_SimpleFunction('session_has', [$this->session, 'has']), |
||
| 367 | new \Twig_SimpleFunction('agent_device', [$this->agent, 'device']), |
||
| 368 | new \Twig_SimpleFunction('agent_browser', [$this->agent, 'browser']), |
||
| 369 | new \Twig_SimpleFunction('agent_platform', [$this->agent, 'platform']), |
||
| 370 | new \Twig_SimpleFunction('agent_is_phone', [$this->agent, 'isPhone']), |
||
| 371 | new \Twig_SimpleFunction('agent_is_robot', [$this->agent, 'isRobot']), |
||
| 372 | new \Twig_SimpleFunction('agent_is_tablet', [$this->agent, 'isTablet']), |
||
| 373 | new \Twig_SimpleFunction('agent_is_mobile', [$this->agent, 'isMobile']), |
||
| 374 | new \Twig_SimpleFunction('agent_is_desktop', [$this->agent, 'isDesktop']), |
||
| 375 | new \Twig_SimpleFunction('asset_add', [$this->asset, 'add']), |
||
| 376 | new \Twig_SimpleFunction('asset_url', [$this->asset, 'url']), |
||
| 377 | new \Twig_SimpleFunction('asset_urls', [$this->asset, 'urls']), |
||
| 378 | new \Twig_SimpleFunction('asset_path', [$this->asset, 'path']), |
||
| 379 | new \Twig_SimpleFunction('asset_paths', [$this->asset, 'paths']), |
||
| 380 | new \Twig_SimpleFunction('asset_download', [$this->asset, 'download']), |
||
| 381 | new \Twig_SimpleFunction('asset_style', [$this->asset, 'style'], ['is_safe' => ['html']]), |
||
| 382 | new \Twig_SimpleFunction('asset_styles', [$this->asset, 'styles'], ['is_safe' => ['html']]), |
||
| 383 | new \Twig_SimpleFunction('asset_inline', [$this->asset, 'inline'], ['is_safe' => ['html']]), |
||
| 384 | new \Twig_SimpleFunction('asset_script', [$this->asset, 'script'], ['is_safe' => ['html']]), |
||
| 385 | new \Twig_SimpleFunction('asset_scripts', [$this->asset, 'scripts'], ['is_safe' => ['html']]) |
||
| 386 | ]; |
||
| 387 | } |
||
| 388 | |||
| 426 |