Conditions | 15 |
Paths | 16 |
Total Lines | 48 |
Code Lines | 23 |
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 |
||
64 | private static function evaluate_requirement( $object, $field, $requirement, $relation ) { |
||
65 | |||
66 | // Test for callables first. |
||
67 | if ( is_callable( $requirement ) ) { |
||
68 | return call_user_func_array( $requirement, array( $field, $object ) ); |
||
69 | } |
||
70 | |||
71 | // Look for comparison array. |
||
72 | if ( is_array( $requirement ) && isset( $requirement['operator'], $requirement['value'], $requirement['setting'] ) ) { |
||
73 | |||
74 | if ( isset( $field['option_name'] ) && '' !== $field['option_name'] ) { |
||
75 | if ( false === strpos( $requirement['setting'], '[' ) ) { |
||
76 | $requirement['setting'] = $field['option_name'] . '[' . $requirement['setting'] . ']'; |
||
77 | } |
||
78 | } |
||
79 | |||
80 | $current_setting = $object->manager->get_setting( $requirement['setting'] ); |
||
81 | |||
82 | /** |
||
83 | * Depending on the 'operator' argument we use, |
||
84 | * we'll need to perform the appropriate comparison |
||
85 | * and figure out if the control will be shown or not. |
||
86 | */ |
||
87 | if ( method_exists( $current_setting, 'value' ) ) { |
||
88 | return self::compare( $requirement['value'], $current_setting->value(), $requirement['operator'] ); |
||
89 | } |
||
90 | } else { |
||
91 | if ( ! is_array( $requirement ) ) { |
||
92 | return true; |
||
93 | } |
||
94 | |||
95 | // Handles "OR/AND" functionality & switching. |
||
96 | $show = false; |
||
97 | $sub_relation = ( 'AND' === $relation ) ? 'OR' : 'AND'; |
||
98 | foreach ( $requirement as $sub_requirement ) { |
||
99 | $show = self::evaluate_requirement( $object, $field, $sub_requirement, $sub_relation ); |
||
100 | if ( 'OR' === $sub_relation && $show ) { |
||
101 | return true; |
||
102 | } |
||
103 | if ( 'AND' === $sub_relation && ! $show ) { |
||
104 | return false; |
||
105 | } |
||
106 | } |
||
107 | return $show; |
||
108 | } |
||
109 | |||
110 | return true; |
||
111 | } |
||
112 | |||
188 |