Completed
Push — master ( b9a8b8...3e8704 )
by Jean-Christophe
03:43
created

PropertyWrapper::wrap()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 8.8571
cc 5
eloc 12
nc 8
nop 4
1
<?php
2
3
namespace Ajax\common\html;
4
5
use Ajax\service\JArray;
6
7
class PropertyWrapper {
8
9
	public static function wrap($input, $js=NULL, $separator=' ', $valueQuote='"') {
0 ignored issues
show
Unused Code introduced by
The parameter $separator is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $valueQuote is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
10
		$output="";
11
		if (is_string($input)) {
12
			$output=$input;
13
		}
14
		if (is_array($input)) {
15
			if (sizeof($input)>0) {
16
				$value1=reset($input);
17
				if (is_object($value1)) {
18
					$output=PropertyWrapper::wrapObjects($input, $js, $separator=' ');
19
				} else
20
					$output=PropertyWrapper::wrapStrings($input, $separator=' ', $valueQuote='"');
21
			}
22
		}
23
		return $output;
24
	}
25
26
	public static function wrapStrings($input, $separator=' ', $valueQuote='"') {
27
		if (JArray::isAssociative($input)===true) {
28
			$result=implode($separator, array_map(function ($v, $k) use($valueQuote) {
29
				return $k.'='.$valueQuote.$v.$valueQuote;
30
			}, $input, array_keys($input)));
31
		} else {
32
			$result=implode($separator, array_values($input));
33
		}
34
		return $result;
35
	}
36
37
	public static function wrapObjects($input, $js=NULL, $separator=' ') {
38
		return implode($separator, array_map(function ($v) use($js) {
39
			if (is_object($v))
40
				return $v->compile($js);
41
			else
42
				return $v;
43
		}, $input));
44
	}
45
}