Code Duplication    Length = 10-10 lines in 2 locations

modules/amp/includes/sanitizers/class-amp-audio-sanitizer.php 1 location

@@ 35-44 (lines=10) @@
32
			$new_node = AMP_DOM_Utils::create_node( $this->dom, 'amp-audio', $new_attributes );
33
34
			// TODO: `source` does not have closing tag, and DOMDocument doesn't handle it well.
35
			foreach ( $node->childNodes as $child_node ) {
36
				$new_child_node = $child_node->cloneNode( true );
37
				$old_child_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array( $new_child_node );
38
				$new_child_attributes = $this->filter_attributes( $old_child_attributes );
39
40
				// Only append source tags with a valid src attribute
41
				if ( ! empty( $new_child_attributes['src'] ) && 'source' === $new_child_node->tagName ) {
42
					$new_node->appendChild( $new_child_node );
43
				}
44
			}
45
46
			// If the node has at least one valid source, replace the old node with it.
47
			// Otherwise, just remove the node.

modules/amp/includes/sanitizers/class-amp-video-sanitizer.php 1 location

@@ 32-41 (lines=10) @@
29
			$new_node = AMP_DOM_Utils::create_node( $this->dom, 'amp-video', $new_attributes );
30
31
			// TODO: `source` does not have closing tag, and DOMDocument doesn't handle it well.
32
			foreach ( $node->childNodes as $child_node ) {
33
				$new_child_node = $child_node->cloneNode( true );
34
				$old_child_attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array( $new_child_node );
35
				$new_child_attributes = $this->filter_attributes( $old_child_attributes );
36
37
				// Only append source tags with a valid src attribute
38
				if ( ! empty( $new_child_attributes['src'] ) && 'source' === $new_child_node->tagName ) {
39
					$new_node->appendChild( $new_child_node );
40
				}
41
			}
42
43
			// If the node has at least one valid source, replace the old node with it.
44
			// Otherwise, just remove the node.