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