ArrayFiller::fill()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 14
cp 0
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 12
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
}