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

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