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

MongoUtilTrait::getNamespacedValue()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
dl 0
loc 14
rs 10
c 1
b 0
f 1
cc 3
nc 3
nop 2
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
}