Completed
Push — add/amp-pwa-experiment ( efea12 )
by
unknown
11:53
created

AMP_HTML_Utils::build_attributes_string()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
class AMP_HTML_Utils {
4
	public static function build_tag( $tag_name, $attributes = array(), $content = '' ) {
5
		$attr_string = self::build_attributes_string( $attributes );
6
		return sprintf( '<%1$s %2$s>%3$s</%1$s>', sanitize_key( $tag_name ), $attr_string, $content );
7
	}
8
9
	public static function build_attributes_string( $attributes ) {
10
		$string = array();
11
		foreach ( $attributes as $name => $value ) {
12
			if ( '' === $value ) {
13
				$string[] = sprintf( '%s', sanitize_key( $name ) );
14
			} else {
15
				$string[] = sprintf( '%s="%s"', sanitize_key( $name ), esc_attr( $value ) );
16
			}
17
		}
18
		return implode( ' ', $string );
19
	}
20
}
21