Conditions | 10 |
Paths | 32 |
Total Lines | 35 |
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 |
||
76 | protected function sanitizeWhereArgsForInputFields( |
||
77 | array $where_args, |
||
78 | array $arg_mapping, |
||
79 | array $id_fields |
||
80 | ) { |
||
81 | $query_args = []; |
||
82 | |||
83 | foreach ($where_args as $arg => $value) { |
||
84 | if (! array_key_exists($arg, $arg_mapping)) { |
||
85 | continue; |
||
86 | } |
||
87 | |||
88 | if (is_array($value) && ! empty($value)) { |
||
89 | $value = array_map( |
||
90 | static function ($value) { |
||
91 | if (is_string($value)) { |
||
92 | $value = sanitize_text_field($value); |
||
93 | } |
||
94 | return $value; |
||
95 | }, |
||
96 | $value |
||
97 | ); |
||
98 | } elseif (is_string($value)) { |
||
99 | $value = sanitize_text_field($value); |
||
100 | } |
||
101 | $query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields) |
||
102 | ? $this->convertGlobalId($value) |
||
103 | : $value; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Return the Query Args |
||
108 | */ |
||
109 | return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
||
110 | } |
||
111 | |||
128 |