| Conditions | 8 |
| Paths | 1 |
| Total Lines | 308 |
| Code Lines | 203 |
| Lines | 34 |
| Ratio | 11.04 % |
| 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 namespace Anomaly\Streams\Platform; |
||
| 209 | public function getFunctions() |
||
| 210 | { |
||
| 211 | return [ |
||
| 212 | new \Twig_SimpleFunction( |
||
| 213 | 'stream', |
||
| 214 | function ($namespace, $slug = null) { |
||
| 215 | return (new Decorator())->decorate( |
||
| 216 | $this->dispatch(new GetStream($namespace, $slug ?: $namespace)) |
||
| 217 | ); |
||
| 218 | } |
||
| 219 | ), |
||
| 220 | new \Twig_SimpleFunction( |
||
| 221 | 'streams', |
||
| 222 | function ($namespace) { |
||
| 223 | return (new Decorator())->decorate( |
||
| 224 | $this->dispatch(new GetStreams($namespace)) |
||
| 225 | ); |
||
| 226 | } |
||
| 227 | ), |
||
| 228 | new \Twig_SimpleFunction( |
||
| 229 | 'entry', |
||
| 230 | function ($namespace, $stream = null) { |
||
| 231 | return (new Decorator())->decorate( |
||
| 232 | $this->dispatch(new GetEntryCriteria($namespace, $stream ?: $namespace, 'first')) |
||
| 233 | ); |
||
| 234 | } |
||
| 235 | ), |
||
| 236 | new \Twig_SimpleFunction( |
||
| 237 | 'entries', |
||
| 238 | function ($namespace, $stream = null) { |
||
| 239 | return (new Decorator())->decorate( |
||
| 240 | $this->dispatch(new GetEntryCriteria($namespace, $stream ?: $namespace, 'get')) |
||
| 241 | ); |
||
| 242 | } |
||
| 243 | ), |
||
| 244 | new \Twig_SimpleFunction( |
||
| 245 | 'query', |
||
| 246 | function ($model = null) { |
||
| 247 | return (new Decorator())->decorate( |
||
| 248 | $this->dispatch(new GetEloquentCriteria($model, 'get')) |
||
| 249 | ); |
||
| 250 | } |
||
| 251 | ), |
||
| 252 | new \Twig_SimpleFunction( |
||
| 253 | 'image_path', |
||
| 254 | function ($image) { |
||
| 255 | return $this->dispatch(new MakeImagePath($image)); |
||
| 256 | } |
||
| 257 | ), |
||
| 258 | new \Twig_SimpleFunction( |
||
| 259 | 'image_url', |
||
| 260 | function ($image) { |
||
| 261 | return $this->dispatch(new MakeImageUrl($image)); |
||
| 262 | } |
||
| 263 | ), |
||
| 264 | new \Twig_SimpleFunction( |
||
| 265 | 'image', |
||
| 266 | function ($image) { |
||
| 267 | return $this->dispatch(new MakeImageTag($image)); |
||
| 268 | }, |
||
| 269 | [ |
||
| 270 | 'is_safe' => ['html'], |
||
| 271 | ] |
||
| 272 | ), |
||
| 273 | new \Twig_SimpleFunction( |
||
| 274 | 'img', |
||
| 275 | function ($image) { |
||
| 276 | return $this->dispatch(new MakeImageTag($image)); |
||
| 277 | }, |
||
| 278 | [ |
||
| 279 | 'is_safe' => ['html'], |
||
| 280 | ] |
||
| 281 | ), |
||
| 282 | new \Twig_SimpleFunction( |
||
| 283 | 'form', |
||
| 284 | function () { |
||
| 285 | $arguments = func_get_args(); |
||
| 286 | |||
| 287 | if (count($arguments) >= 2) { |
||
| 288 | $arguments = [ |
||
| 289 | 'namespace' => array_get(func_get_args(), 0), |
||
| 290 | 'stream' => array_get(func_get_args(), 1), |
||
| 291 | 'entry' => array_get(func_get_args(), 2), |
||
| 292 | ]; |
||
| 293 | } |
||
| 294 | |||
| 295 | if (count($arguments) == 1) { |
||
| 296 | $arguments = func_get_arg(0); |
||
| 297 | } |
||
| 298 | |||
| 299 | return $this->dispatch(new GetFormCriteria($arguments)); |
||
| 300 | }, |
||
| 301 | [ |
||
| 302 | 'is_safe' => ['html'], |
||
| 303 | ] |
||
| 304 | ), |
||
| 305 | new \Twig_SimpleFunction( |
||
| 306 | 'icon', |
||
| 307 | function ($type, $class = null) { |
||
| 308 | return (new Decorator())->decorate($this->dispatch(new GetIcon($type, $class))); |
||
| 309 | }, |
||
| 310 | [ |
||
| 311 | 'is_safe' => ['html'], |
||
| 312 | ] |
||
| 313 | ), |
||
| 314 | new \Twig_SimpleFunction( |
||
| 315 | 'view', |
||
| 316 | function ($view, array $data = []) { |
||
| 317 | return $this->dispatch(new GetView($view, $data))->render(); |
||
| 318 | }, |
||
| 319 | [ |
||
| 320 | 'is_safe' => ['html'], |
||
| 321 | ] |
||
| 322 | ), |
||
| 323 | new \Twig_SimpleFunction( |
||
| 324 | 'buttons', |
||
| 325 | function ($buttons) { |
||
| 326 | return $this->dispatch(new GetButtons($buttons))->render(); |
||
| 327 | }, |
||
| 328 | [ |
||
| 329 | 'is_safe' => ['html'], |
||
| 330 | ] |
||
| 331 | ), |
||
| 332 | new \Twig_SimpleFunction( |
||
| 333 | 'constants', |
||
| 334 | function () { |
||
| 335 | return $this->dispatch(new GetConstants())->render(); |
||
| 336 | }, |
||
| 337 | [ |
||
| 338 | 'is_safe' => ['html'], |
||
| 339 | ] |
||
| 340 | ), |
||
| 341 | new \Twig_SimpleFunction( |
||
| 342 | 'env', |
||
| 343 | function ($key, $default = null) { |
||
| 344 | return env($key, $default); |
||
| 345 | } |
||
| 346 | ), |
||
| 347 | new \Twig_SimpleFunction( |
||
| 348 | 'carbon', |
||
| 349 | function ($time = null, $timezone = null) { |
||
| 350 | return new Carbon($time, $timezone); |
||
| 351 | } |
||
| 352 | ), |
||
| 353 | new \Twig_SimpleFunction( |
||
| 354 | 'decorate', |
||
| 355 | function ($value) { |
||
| 356 | return (new Decorator())->decorate($value); |
||
| 357 | } |
||
| 358 | ), |
||
| 359 | new \Twig_SimpleFunction( |
||
| 360 | 'request_time', |
||
| 361 | function ($decimal = 2) { |
||
| 362 | return $this->dispatch(new GetElapsedTime($decimal)); |
||
| 363 | } |
||
| 364 | ), |
||
| 365 | new \Twig_SimpleFunction( |
||
| 366 | 'memory_usage', |
||
| 367 | function ($precision = 1) { |
||
| 368 | return $this->dispatch(new GetMemoryUsage($precision)); |
||
| 369 | } |
||
| 370 | ), |
||
| 371 | new \Twig_SimpleFunction( |
||
| 372 | 'layout', |
||
| 373 | function ($layout, $default = 'default') { |
||
| 374 | return $this->dispatch(new GetLayoutName($layout, $default)); |
||
| 375 | } |
||
| 376 | ), |
||
| 377 | new \Twig_SimpleFunction( |
||
| 378 | 'request_*', |
||
| 379 | View Code Duplication | function ($name) { |
|
| 380 | $arguments = array_slice(func_get_args(), 1); |
||
| 381 | |||
| 382 | return call_user_func_array([$this->request, camel_case($name)], $arguments); |
||
| 383 | } |
||
| 384 | ), |
||
| 385 | new \Twig_SimpleFunction( |
||
| 386 | 'trans', |
||
| 387 | function ($key, array $parameters = [], $locale = 'en') { |
||
| 388 | return $this->dispatch(new GetTranslatedString($key, $parameters, $locale)); |
||
| 389 | } |
||
| 390 | ), |
||
| 391 | new \Twig_SimpleFunction( |
||
| 392 | 'str_*', |
||
| 393 | View Code Duplication | function ($name) { |
|
| 394 | $arguments = array_slice(func_get_args(), 1); |
||
| 395 | |||
| 396 | return call_user_func_array([$this->str, camel_case($name)], $arguments); |
||
| 397 | } |
||
| 398 | ), |
||
| 399 | new \Twig_SimpleFunction( |
||
| 400 | 'url_*', |
||
| 401 | View Code Duplication | function ($name) { |
|
| 402 | $arguments = array_slice(func_get_args(), 1); |
||
| 403 | |||
| 404 | return call_user_func_array([$this->url, camel_case($name)], $arguments); |
||
| 405 | } |
||
| 406 | ), |
||
| 407 | new \Twig_SimpleFunction( |
||
| 408 | 'route_*', |
||
| 409 | View Code Duplication | function ($name) { |
|
| 410 | $arguments = array_slice(func_get_args(), 1); |
||
| 411 | |||
| 412 | return call_user_func_array([$this->route, camel_case($name)], $arguments); |
||
| 413 | } |
||
| 414 | ), |
||
| 415 | new \Twig_SimpleFunction( |
||
| 416 | 'asset_*', |
||
| 417 | View Code Duplication | function ($name) { |
|
| 418 | $arguments = array_slice(func_get_args(), 1); |
||
| 419 | |||
| 420 | return call_user_func_array([$this->asset, camel_case($name)], $arguments); |
||
| 421 | }, ['is_safe' => ['html']] |
||
| 422 | ), |
||
| 423 | new \Twig_SimpleFunction( |
||
| 424 | 'currency_*', |
||
| 425 | View Code Duplication | function ($name) { |
|
| 426 | $arguments = array_slice(func_get_args(), 1); |
||
| 427 | |||
| 428 | return call_user_func_array([$this->currency, camel_case($name)], $arguments); |
||
| 429 | } |
||
| 430 | ), |
||
| 431 | new \Twig_SimpleFunction( |
||
| 432 | 'yaml', |
||
| 433 | function ($input) { |
||
| 434 | |||
| 435 | if ($input instanceof FieldTypePresenter) { |
||
| 436 | $input = $input->__toString(); |
||
| 437 | } |
||
| 438 | |||
| 439 | return $this->yaml->parse($input); |
||
| 440 | } |
||
| 441 | ), |
||
| 442 | new \Twig_SimpleFunction( |
||
| 443 | 'addon', |
||
| 444 | function ($identifier) { |
||
| 445 | return (new Decorator())->decorate(app(AddonCollection::class)->get($identifier)); |
||
| 446 | } |
||
| 447 | ), |
||
| 448 | new \Twig_SimpleFunction( |
||
| 449 | 'addons', |
||
| 450 | function ($type = null) { |
||
| 451 | $addons = app(AddonCollection::class); |
||
| 452 | |||
| 453 | if ($type) { |
||
| 454 | $addons = $addons->{str_plural($type)}(); |
||
| 455 | } |
||
| 456 | |||
| 457 | return (new Decorator())->decorate($addons); |
||
| 458 | } |
||
| 459 | ), |
||
| 460 | new \Twig_SimpleFunction( |
||
| 461 | 'breadcrumb', |
||
| 462 | function () { |
||
| 463 | return app(BreadcrumbCollection::class); |
||
| 464 | }, ['is_safe' => ['html']] |
||
| 465 | ), |
||
| 466 | new \Twig_SimpleFunction( |
||
| 467 | 'gravatar', |
||
| 468 | function ($email, array $parameters = []) { |
||
| 469 | return $this->image->make( |
||
| 470 | 'https://www.gravatar.com/avatar/' . md5($email) . '?' . http_build_query( |
||
| 471 | $parameters |
||
| 472 | ), |
||
| 473 | 'image' |
||
| 474 | ); |
||
| 475 | }, ['is_safe' => ['html']] |
||
| 476 | ), |
||
| 477 | new \Twig_SimpleFunction( |
||
| 478 | 'cookie', |
||
| 479 | function ($key, $default = null) { |
||
| 480 | return array_get($_COOKIE, $key, $default); |
||
| 481 | } |
||
| 482 | ), |
||
| 483 | new \Twig_SimpleFunction('input_get', [$this->request, 'input']), |
||
| 484 | new \Twig_SimpleFunction('asset', [$this->url, 'asset'], ['is_safe' => ['html']]), |
||
| 485 | new \Twig_SimpleFunction('action', [$this->url, 'action'], ['is_safe' => ['html']]), |
||
| 486 | new \Twig_SimpleFunction('url', [$this, 'url'], ['is_safe' => ['html']]), |
||
| 487 | new \Twig_SimpleFunction('route', [$this->url, 'route'], ['is_safe' => ['html']]), |
||
| 488 | new \Twig_SimpleFunction('route_has', [$this->router, 'has'], ['is_safe' => ['html']]), |
||
| 489 | new \Twig_SimpleFunction('secure_url', [$this->url, 'secure'], ['is_safe' => ['html']]), |
||
| 490 | new \Twig_SimpleFunction('secure_asset', [$this->url, 'secureAsset'], ['is_safe' => ['html']]), |
||
| 491 | new \Twig_SimpleFunction('config', [$this->config, 'get']), |
||
| 492 | new \Twig_SimpleFunction('config_get', [$this->config, 'get']), |
||
| 493 | new \Twig_SimpleFunction('config_has', [$this->config, 'has']), |
||
| 494 | new \Twig_SimpleFunction('auth_user', [$this->auth, 'user']), |
||
| 495 | new \Twig_SimpleFunction('auth_check', [$this->auth, 'check']), |
||
| 496 | new \Twig_SimpleFunction('auth_guest', [$this->auth, 'guest']), |
||
| 497 | new \Twig_SimpleFunction('trans_exists', [$this->translator, 'exists']), |
||
| 498 | new \Twig_SimpleFunction('message_get', [$this->session, 'pull']), |
||
| 499 | new \Twig_SimpleFunction('message_exists', [$this->session, 'has']), |
||
| 500 | new \Twig_SimpleFunction('session', [$this->session, 'get']), |
||
| 501 | new \Twig_SimpleFunction('parse', [$this->template, 'render'], ['is_safe' => ['html']]), |
||
| 502 | new \Twig_SimpleFunction('csrf_token', [$this->session, 'token'], ['is_safe' => ['html']]), |
||
| 503 | new \Twig_SimpleFunction('csrf_field', 'csrf_field', ['is_safe' => ['html']]), |
||
| 504 | new \Twig_SimpleFunction('session_get', [$this->session, 'get']), |
||
| 505 | new \Twig_SimpleFunction('session_pull', [$this->session, 'pull']), |
||
| 506 | new \Twig_SimpleFunction('session_has', [$this->session, 'has']), |
||
| 507 | new \Twig_SimpleFunction('agent_device', [$this->agent, 'device']), |
||
| 508 | new \Twig_SimpleFunction('agent_browser', [$this->agent, 'browser']), |
||
| 509 | new \Twig_SimpleFunction('agent_platform', [$this->agent, 'platform']), |
||
| 510 | new \Twig_SimpleFunction('agent_is_phone', [$this->agent, 'isPhone']), |
||
| 511 | new \Twig_SimpleFunction('agent_is_robot', [$this->agent, 'isRobot']), |
||
| 512 | new \Twig_SimpleFunction('agent_is_tablet', [$this->agent, 'isTablet']), |
||
| 513 | new \Twig_SimpleFunction('agent_is_mobile', [$this->agent, 'isMobile']), |
||
| 514 | new \Twig_SimpleFunction('agent_is_desktop', [$this->agent, 'isDesktop']), |
||
| 515 | ]; |
||
| 516 | } |
||
| 517 | |||
| 554 |