Completed
Push — master ( 424d4e...c1a616 )
by Jean-Christophe
03:24
created

JArray   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 10
c 5
b 0
f 1
lcom 0
cbo 0
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isAssociative() 0 3 1
A getValue() 0 8 3
A getDefaultValue() 0 6 2
A implode() 0 15 4
1
<?php
2
3
namespace Ajax\service;
4
5
class JArray {
6
7
	public static function isAssociative($array) {
8
		return (array_keys($array)!==range(0, count($array)-1));
9
	}
10
11
	public static function getValue($array, $key, $pos) {
12
		if (array_key_exists($key, $array)) {
13
			return $array [$key];
14
		}
15
		$values=array_values($array);
16
		if ($pos<sizeof($values))
17
			return $values [$pos];
18
	}
19
20
	public static function getDefaultValue($array, $key, $default) {
21
		if (array_key_exists($key, $array)) {
22
			return $array [$key];
23
		} else
24
			return $default;
25
	}
26
27
	public static function implode($glue,$pieces){
28
		$result="";
29
		if(\is_array($glue)){
30
			$size=\sizeof($pieces);
31
			if($size>0){
32
				for($i=0;$i<$size-1;$i++){
33
					$result.=$pieces[$i].@$glue[$i];
34
				}
35
				$result.=$pieces[$size-1];
36
			}
37
		}else{
38
			$result=\implode($glue, $pieces);
39
		}
40
		return $result;
41
	}
42
}