ArrayUtil   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
c 2
b 0
f 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A only() 0 3 1
A converToObject() 0 9 2
A check() 0 11 3
A except() 0 3 1
1
<?php
2
3
namespace PlugHttp\Utils;
4
5
class ArrayUtil
6
{
7
	public static function only(array $data, array $accept)
8
	{
9
		return self::check($data, $accept, true);
10
	}
11
12
	public static function except(array $data, array $except)
13
	{
14
		return self::check($data, $except, false);
15
	}
16
17
	private static function check($data, $keys, $in)
18
	{
19
		$array = [];
20
21
		foreach ($data as $k => $v) {
22
			if (in_array($k, $keys) === $in) {
23
				$array[$k] = $v;
24
			}
25
		}
26
27
		return $array;
28
	}
29
30
    public static function converToObject(array $data)
31
    {
32
        $object = new \stdClass();
33
34
        foreach ($data as $key => $value) {
35
            $object->$key = $value;
36
        }
37
38
        return $object;
39
	}
40
}