Passed
Push — master ( abee1f...edc958 )
by Kirill
03:08
created

DotTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dotGet() 0 17 6
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Config\Patch\Traits;
13
14
use Spiral\Config\Exception\DotNotFoundException;
15
16
trait DotTrait
17
{
18
    /**
19
     * @param array  $data Pointer.
20
     * @param string $name
21
     * @return array|mixed
22
     */
23
    private function &dotGet(array &$data, string $name)
24
    {
25
        //Generating path relative to a given name and prefix
26
        $path = (!empty($this->prefix) ? $this->prefix . '.' : '') . $name;
27
        if (empty($path)) {
28
            return $data;
29
        }
30
31
        $path = explode('.', rtrim($path, '.'));
32
        foreach ($path as $step) {
33
            if (!is_array($data) || !array_key_exists($step, $data)) {
34
                throw new DotNotFoundException("Unable to find config element '{$name}'.");
35
            }
36
            $data = &$data[$step];
37
        }
38
39
        return $data;
40
    }
41
}
42