Passed
Push — master ( fae764...86e9e2 )
by Php Easy Api
04:24
created

ContainerClosureResolver::get()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 37
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 18
nc 9
nop 1
dl 0
loc 37
rs 8.0555
c 1
b 0
f 0
1
<?php
2
3
namespace Resta\Container;
4
5
use Resta\Support\JsonHandler;
6
use Resta\Support\SuperClosure;
7
use Resta\Exception\FileNotFoundException;
8
9
class ContainerClosureResolver
10
{
11
    /**
12
     * container resolver service json file
13
     *
14
     * @param $key
15
     * @return mixed|null
16
     *
17
     * @throws FileNotFoundException
18
     */
19
    public static function get($key)
20
    {
21
        if(file_exists(serviceJson())){
22
            JsonHandler::$file = serviceJson();
23
            $serviceJson = JsonHandler::get();
24
25
            $dottedKey = explode('.',$key);
26
27
            if(count($dottedKey)==2){
28
29
                if(isset($serviceJson['container'][$dottedKey[0]][$dottedKey[1]])){
30
                    $arrayData = $serviceJson['container'][$dottedKey[0]][$dottedKey[1]];
31
32
                    if($serviceJson['container-format'][$dottedKey[0]][$dottedKey[1]]=='string'){
33
                        return $arrayData;
34
                    }
35
36
                    if($serviceJson['container-format'][$dottedKey[0]][$dottedKey[1]]=='closure'){
37
                        return SuperClosure::get($arrayData);
38
                    }
39
                }
40
            }
41
            else{
42
43
                if(isset($serviceJson['container'][$key])){
44
                    if($serviceJson['container-format'][$key]=='string'){
45
                        return $serviceJson['container'][$key];
46
                    }
47
48
                    if($serviceJson['container-format'][$key]=='closure'){
49
                        return SuperClosure::get($serviceJson['container'][$key]);
50
                    }
51
                }
52
            }
53
        }
54
55
        return null;
56
    }
57
}