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

AMP_HTML_Utils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build_tag() 0 4 1
A build_attributes_string() 0 11 3
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