ArrayFiller   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 25
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fill() 0 14 3
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL-3.0-only, proprietary` license[s].
5
 *
6
 * @package maslosoft/manganel
7
 * @license AGPL-3.0-only, proprietary
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/manganel/
11
 */
12
13
namespace Maslosoft\Manganel\Helpers;
14
15
16
use function array_key_exists;
17
18
class ArrayFiller
19
{
20
	/**
21
	 * Fill array by path. This will
22
	 * create array keys if not already set.
23
	 *
24
	 * @param $array
25
	 * @param $path
26
	 * @param $value
27
	 */
28
	public static function fill($array, $path, $value)
29
	{
30
		$parts = explode('.', $path);
31
		$key = array_shift($parts);
32
		if (empty($path))
33
		{
34
			return $value;
35
		}
36
		if (!array_key_exists($key, $array))
37
		{
38
			$array[$key] = self::fill($array, implode('.', $parts), $value);
39
		}
40
		return $array;
41
	}
42
}