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

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