Completed
Push — master ( 8f9aa0...67ca79 )
by Tom
8s
created

Json   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 23
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 15 4
1
<?php
2
namespace Transphporm\TSSFunction;
3
class Json implements \Transphporm\TSSFunction {
4
        private $baseDir;
5
        
6
        public function __construct(&$baseDir) {
7
                $this->baseDir = &$baseDir;
8
        }
9
        
10
        public function run(array $args, \DomElement $element = null) {
11
                $json = $args[0];
12
                
13
                if (trim($json)[0] != '{') {
14
                        $path = $this->baseDir . $json;
15
                        if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path);
16
			$json = file_get_contents($json);
17
		}
18
19
		$map = json_decode($json, true);
20
                
21
                if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg());
22
                
23
                return $map;
24
        }
25
}
26