| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| Lines | 30 |
| Ratio | 55.56 % |
| 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 |
||
| 68 | protected function registerBladeExtensions() |
||
| 69 | { |
||
| 70 | $this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) { |
||
| 71 | View Code Duplication | $bladeCompiler->directive('role', function ($arguments) { |
|
| 72 | list($role, $guard) = explode(',', $arguments.','); |
||
| 73 | |||
| 74 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>"; |
||
| 75 | }); |
||
| 76 | View Code Duplication | $bladeCompiler->directive('elserole', function ($arguments) { |
|
| 77 | list($role, $guard) = explode(',', $arguments.','); |
||
| 78 | |||
| 79 | return "<?php elseif(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>"; |
||
| 80 | }); |
||
| 81 | $bladeCompiler->directive('endrole', function () { |
||
| 82 | return '<?php endif; ?>'; |
||
| 83 | }); |
||
| 84 | |||
| 85 | View Code Duplication | $bladeCompiler->directive('hasrole', function ($arguments) { |
|
| 86 | list($role, $guard) = explode(',', $arguments.','); |
||
| 87 | |||
| 88 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasRole({$role})): ?>"; |
||
| 89 | }); |
||
| 90 | $bladeCompiler->directive('endhasrole', function () { |
||
| 91 | return '<?php endif; ?>'; |
||
| 92 | }); |
||
| 93 | |||
| 94 | View Code Duplication | $bladeCompiler->directive('hasanyrole', function ($arguments) { |
|
| 95 | list($roles, $guard) = explode(',', $arguments.','); |
||
| 96 | |||
| 97 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAnyRole({$roles})): ?>"; |
||
| 98 | }); |
||
| 99 | $bladeCompiler->directive('endhasanyrole', function () { |
||
| 100 | return '<?php endif; ?>'; |
||
| 101 | }); |
||
| 102 | |||
| 103 | View Code Duplication | $bladeCompiler->directive('hasallroles', function ($arguments) { |
|
| 104 | list($roles, $guard) = explode(',', $arguments.','); |
||
| 105 | |||
| 106 | return "<?php if(auth({$guard})->check() && auth({$guard})->user()->hasAllRoles({$roles})): ?>"; |
||
| 107 | }); |
||
| 108 | $bladeCompiler->directive('endhasallroles', function () { |
||
| 109 | return '<?php endif; ?>'; |
||
| 110 | }); |
||
| 111 | |||
| 112 | View Code Duplication | $bladeCompiler->directive('unlessrole', function ($arguments) { |
|
| 113 | list($role, $guard) = explode(',', $arguments.','); |
||
| 114 | |||
| 115 | return "<?php if(!auth({$guard})->check() || ! auth({$guard})->user()->hasRole({$role})): ?>"; |
||
| 116 | }); |
||
| 117 | $bladeCompiler->directive('endunlessrole', function () { |
||
| 118 | return '<?php endif; ?>'; |
||
| 119 | }); |
||
| 120 | }); |
||
| 121 | } |
||
| 122 | |||
| 171 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.