Code Duplication    Length = 33-34 lines in 2 locations

core/EES_Shortcode.shortcode.php 1 location

@@ 157-189 (lines=33) @@
154
     */
155
    public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
156
    {
157
        foreach ($attributes as $key => $value) {
158
            // is a custom sanitization callback specified ?
159
            if ( isset($custom_sanitization[$key])) {
160
                $callback = $custom_sanitization[$key];
161
                if ($callback === 'skip_sanitization') {
162
                    $attributes[$key] = $value;
163
                    continue;
164
                } else if (function_exists($callback)){
165
                    $attributes[$key] = $callback($value);
166
                    continue;
167
                }
168
            }
169
            switch (true) {
170
                case $value === null :
171
                case is_int($value) :
172
                case is_float($value) :
173
                    // typical booleans
174
                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
175
                    $attributes[$key] = $value;
176
                    break;
177
                case is_string($value) :
178
                    $attributes[$key] = sanitize_text_field($value);
179
                    break;
180
                case is_array($value) :
181
                    $attributes[$key] = \EES_Shortcode::sanitize_attributes($value);
182
                    break;
183
                default :
184
                    // only remaining data types are Object and Resource
185
                    // which are not allowed as shortcode attributes
186
                    $attributes[$key] = null;
187
                    break;
188
            }
189
        }
190
        return $attributes;
191
	}
192

core/services/shortcodes/EspressoShortcode.php 1 location

@@ 204-237 (lines=34) @@
201
    private function sanitizeAttributes(array $attributes)
202
    {
203
        $custom_sanitization = $this->customAttributeSanitizationMap();
204
        foreach ($attributes as $key => $value) {
205
            // is a custom sanitization callback specified ?
206
            if (isset($custom_sanitization[$key])) {
207
                $callback = $custom_sanitization[$key];
208
                if ($callback === 'skip_sanitization') {
209
                    $attributes[$key] = $value;
210
                    continue;
211
                }
212
                if (function_exists($callback)) {
213
                    $attributes[$key] = $callback($value);
214
                    continue;
215
                }
216
            }
217
            switch (true) {
218
                case $value === null :
219
                case is_int($value) :
220
                case is_float($value) :
221
                    // typical booleans
222
                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
223
                    $attributes[$key] = $value;
224
                    break;
225
                case is_string($value) :
226
                    $attributes[$key] = sanitize_text_field($value);
227
                    break;
228
                case is_array($value) :
229
                    $attributes[$key] = $this->sanitizeAttributes($value);
230
                    break;
231
                default :
232
                    // only remaining data types are Object and Resource
233
                    // which are not allowed as shortcode attributes
234
                    $attributes[$key] = null;
235
                    break;
236
            }
237
        }
238
        return $attributes;
239
    }
240