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

ContainerClosureResolver   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B get() 0 37 9
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
}