Completed
Push — master ( 63d3cc...fb2a6e )
by Peter
06:57
created

ArrayFiller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fill() 0 14 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 08.03.18
6
 * Time: 17:12
7
 */
8
9
namespace Maslosoft\Manganel\Helpers;
10
11
12
use function array_key_exists;
13
14
class ArrayFiller
15
{
16
	/**
17
	 * Fill array by path. This will
18
	 * create array keys if not already set.
19
	 *
20
	 * @param $array
21
	 * @param $path
22
	 * @param $value
23
	 */
24 5
	public static function fill($array, $path, $value)
25
	{
26 5
		$parts = explode('.', $path);
27 5
		$key = array_shift($parts);
28 5
		if (empty($path))
29
		{
30 5
			return $value;
31
		}
32 5
		if (!array_key_exists($key, $array))
33
		{
34 5
			$array[$key] = self::fill($array, implode('.', $parts), $value);
35
		}
36 5
		return $array;
37
	}
38
}