Passed
Pull Request — master (#631)
by ANTHONIUS
08:16
created

MongoUtilTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 9
dl 0
loc 23
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getNamespacedValue() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yawik\Migration\Util;
6
7
8
trait MongoUtilTrait
9
{
10
    /**
11
     * Get value from namespaced key
12
     *
13
     * @param string $nsKey
14
     * @param array $subject
15
     * @return mixed
16
     */
17
    protected function getNamespacedValue(string $nsKey, array $subject)
18
    {
19
        $exp = explode('.', $nsKey);
20
21
        $value = null;
22
        $cSubject = $subject;
23
        foreach($exp as $name){
24
            if(array_key_exists($name, $cSubject)){
25
                $value = $cSubject[$name];
26
                $cSubject = $cSubject[$name];
27
            }
28
        }
29
30
        return $value;
31
    }
32
}