| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 19 |
| CRAP Score | 1 |
| 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 |
||
| 13 | 1 | public function register(Container $dic) |
|
| 14 | { |
||
| 15 | |||
| 16 | |||
| 17 | /** |
||
| 18 | * @return StdClass |
||
| 19 | */ |
||
| 20 | 4 | $dic['Roles.Config'] = function( $dic ) { |
|
|
|
|||
| 21 | return (object) [ |
||
| 22 | 3 | 'all' => [ |
|
| 23 | 2 | 'guest' => 1, |
|
| 24 | 1 | 'registered' => 2, |
|
| 25 | 1 | 'superuser' => 3, |
|
| 26 | 'admin' => 4 |
||
| 27 | 1 | ], |
|
| 28 | |||
| 29 | 1 | "guests" => [ 1 ], |
|
| 30 | 1 | "new_users" => [ 2 ] |
|
| 31 | 1 | ]; |
|
| 32 | }; |
||
| 33 | |||
| 34 | |||
| 35 | 4 | $dic['Roles.pdo'] = function( $dic ) { |
|
| 36 | 5 | return false; |
|
| 37 | }; |
||
| 38 | |||
| 39 | |||
| 40 | /** |
||
| 41 | * @return StdClass |
||
| 42 | */ |
||
| 43 | 4 | $dic['Roles.all'] = function( $dic ) { |
|
| 44 | 5 | return (object) $dic['Roles.Config']->all; |
|
| 45 | }; |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | 4 | $dic['Roles.guests'] = function( $dic ) { |
|
| 52 | 5 | return $dic['Roles.Config']->guests; |
|
| 53 | }; |
||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * @return array |
||
| 58 | */ |
||
| 59 | 5 | $dic['Roles.new_users'] = function( $dic ) { |
|
| 60 | 5 | return $dic['Roles.Config']->new_users; |
|
| 61 | }; |
||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | |||
| 68 | 5 | } |
|
| 69 | } |
||
| 71 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.