| Conditions | 1 |
| Paths | 1 |
| Total Lines | 99 |
| Code Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 26 | protected static function install_conditions( $ioc ) { |
||
| 27 | $ioc['container_condition_type_boolean'] = $ioc->factory( function( $ioc ) { |
||
| 28 | return new \Carbon_Fields\Container\Condition\Boolean_Condition( array( |
||
| 29 | $ioc['container_condition_comparer_type_equality'], |
||
| 30 | ) ); |
||
| 31 | } ); |
||
| 32 | $ioc['container_condition_type_post_id'] = $ioc->factory( function( $ioc ) { |
||
| 33 | return new \Carbon_Fields\Container\Condition\Post_ID_Condition( $ioc['container_condition_comparers_generic'] ); |
||
| 34 | } ); |
||
| 35 | $ioc['container_condition_type_post_parent_id'] = $ioc->factory( function( $ioc ) { |
||
| 36 | return new \Carbon_Fields\Container\Condition\Post_Parent_ID_Condition( $ioc['container_condition_comparers_generic'] ); |
||
| 37 | } ); |
||
| 38 | $ioc['container_condition_type_post_type'] = $ioc->factory( function( $ioc ) { |
||
| 39 | return new \Carbon_Fields\Container\Condition\Post_Type_Condition( $ioc['container_condition_comparers_wo_scalar'] ); |
||
| 40 | } ); |
||
| 41 | $ioc['container_condition_type_post_format'] = $ioc->factory( function( $ioc ) { |
||
| 42 | return new \Carbon_Fields\Container\Condition\Post_Format_Condition( $ioc['container_condition_comparers_wo_scalar'] ); |
||
| 43 | } ); |
||
| 44 | $ioc['container_condition_type_post_level'] = $ioc->factory( function( $ioc ) { |
||
| 45 | return new \Carbon_Fields\Container\Condition\Post_Level_Condition( $ioc['container_condition_comparers_generic'] ); |
||
| 46 | } ); |
||
| 47 | $ioc['container_condition_type_post_template'] = $ioc->factory( function( $ioc ) { |
||
| 48 | return new \Carbon_Fields\Container\Condition\Post_Template_Condition( $ioc['container_condition_comparers_wo_scalar'] ); |
||
| 49 | } ); |
||
| 50 | $ioc['container_condition_type_post_term'] = $ioc->factory( function( $ioc ) { |
||
| 51 | return new \Carbon_Fields\Container\Condition\Post_Term_Condition( array( |
||
| 52 | // Only support the custom comparer as this condition has it's own comparison methods |
||
| 53 | $ioc['container_condition_comparer_type_custom'], |
||
| 54 | ) ); |
||
| 55 | } ); |
||
| 56 | |||
| 57 | $ioc['container_condition_type_term'] = $ioc->factory( function( $ioc ) { |
||
| 58 | return new \Carbon_Fields\Container\Condition\Term_Condition( $ioc['container_condition_comparers_wo_scalar'] ); |
||
| 59 | } ); |
||
| 60 | $ioc['container_condition_type_term_taxonomy'] = $ioc->factory( function( $ioc ) { |
||
| 61 | return new \Carbon_Fields\Container\Condition\Term_Taxonomy_Condition( $ioc['container_condition_comparers_wo_scalar'] ); |
||
| 62 | } ); |
||
| 63 | $ioc['container_condition_type_term_level'] = $ioc->factory( function( $ioc ) { |
||
| 64 | return new \Carbon_Fields\Container\Condition\Term_Level_Condition( $ioc['container_condition_comparers_generic'] ); |
||
| 65 | } ); |
||
| 66 | |||
| 67 | $ioc['container_condition_type_user_id'] = $ioc->factory( function( $ioc ) { |
||
| 68 | return new \Carbon_Fields\Container\Condition\User_ID_Condition( $ioc['container_condition_comparers_generic'] ); |
||
| 69 | } ); |
||
| 70 | $ioc['container_condition_type_user_role'] = $ioc->factory( function( $ioc ) { |
||
| 71 | return new \Carbon_Fields\Container\Condition\User_Role_Condition( array( |
||
| 72 | // Only support the custom comparer as this condition has it's own comparison methods |
||
| 73 | $ioc['container_condition_comparer_type_custom'], |
||
| 74 | ) ); |
||
| 75 | } ); |
||
| 76 | $ioc['container_condition_type_user_capabiltiy'] = $ioc->factory( function( $ioc ) { |
||
| 77 | return new \Carbon_Fields\Container\Condition\User_Capability_Condition( array( |
||
| 78 | // Only support the custom comparer as this condition has it's own comparison methods |
||
| 79 | $ioc['container_condition_comparer_type_custom'], |
||
| 80 | ) ); |
||
| 81 | } ); |
||
| 82 | |||
| 83 | $ioc['container_condition_type_current_user_id'] = $ioc->factory( function( $ioc ) { |
||
| 84 | return new \Carbon_Fields\Container\Condition\Current_User_ID_Condition( $ioc['container_condition_comparers_generic'] ); |
||
| 85 | } ); |
||
| 86 | $ioc['container_condition_type_current_user_role'] = $ioc->factory( function( $ioc ) { |
||
| 87 | return new \Carbon_Fields\Container\Condition\Current_User_Role_Condition( array( |
||
| 88 | // Only support the custom comparer as this condition has it's own comparison methods |
||
| 89 | $ioc['container_condition_comparer_type_custom'], |
||
| 90 | ) ); |
||
| 91 | } ); |
||
| 92 | $ioc['container_condition_type_current_user_capability'] = $ioc->factory( function( $ioc ) { |
||
| 93 | return new \Carbon_Fields\Container\Condition\Current_User_Capability_Condition( array( |
||
| 94 | // Only support the custom comparer as this condition has it's own comparison methods |
||
| 95 | $ioc['container_condition_comparer_type_custom'], |
||
| 96 | ) ); |
||
| 97 | } ); |
||
| 98 | |||
| 99 | $ioc['container_condition_factory'] = function() { |
||
| 100 | $factory = new ConditionFactory(); |
||
| 101 | $factory->register( 'boolean', 'Carbon_Fields\\Container\\Condition\\Boolean_Condition' ); |
||
| 102 | |||
| 103 | $factory->register( 'post_id', 'Carbon_Fields\\Container\\Condition\\Post_ID_Condition' ); |
||
| 104 | $factory->register( 'post_parent_id', 'Carbon_Fields\\Container\\Condition\\Post_Parent_ID_Condition' ); |
||
| 105 | $factory->register( 'post_type', 'Carbon_Fields\\Container\\Condition\\Post_Type_Condition' ); |
||
| 106 | $factory->register( 'post_format', 'Carbon_Fields\\Container\\Condition\\Post_Format_Condition' ); |
||
| 107 | $factory->register( 'post_level', 'Carbon_Fields\\Container\\Condition\\Post_Level_Condition' ); |
||
| 108 | $factory->register( 'post_template', 'Carbon_Fields\\Container\\Condition\\Post_Template_Condition' ); |
||
| 109 | $factory->register( 'post_term', 'Carbon_Fields\\Container\\Condition\\Post_Term_Condition' ); |
||
| 110 | |||
| 111 | $factory->register( 'term', 'Carbon_Fields\\Container\\Condition\\Term_Condition' ); |
||
| 112 | $factory->register( 'term_taxonomy', 'Carbon_Fields\\Container\\Condition\\Term_Taxonomy_Condition' ); |
||
| 113 | $factory->register( 'term_level', 'Carbon_Fields\\Container\\Condition\\Term_Level_Condition' ); |
||
| 114 | |||
| 115 | $factory->register( 'user_id', 'Carbon_Fields\\Container\\Condition\\User_ID_Condition' ); |
||
| 116 | $factory->register( 'user_role', 'Carbon_Fields\\Container\\Condition\\User_Role_Condition' ); |
||
| 117 | $factory->register( 'user_capability', 'Carbon_Fields\\Container\\Condition\\User_Capability_Condition' ); |
||
| 118 | |||
| 119 | $factory->register( 'current_user_id', 'Carbon_Fields\\Container\\Condition\\Current_User_ID_Condition' ); |
||
| 120 | $factory->register( 'current_user_role', 'Carbon_Fields\\Container\\Condition\\Current_User_Role_Condition' ); |
||
| 121 | $factory->register( 'current_user_capability', 'Carbon_Fields\\Container\\Condition\\Current_User_Capability_Condition' ); |
||
| 122 | return $factory; |
||
| 123 | }; |
||
| 124 | } |
||
| 125 | |||
| 168 | } |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: