Completed
Push — php7.2-travis ( 83e6ee...46fda5 )
by
unknown
265:12 queued 251:40
created

ar_template   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 23.4%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 11
cts 47
cp 0.234
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
B getStorageLayer() 0 23 6
A save() 0 3 1
A load() 0 3 1
A ls() 0 6 2
A rm() 0 3 1
A exists() 0 3 1
A compile() 0 3 1
A get() 0 6 2
1
<?php
2
3
	class ar_template extends arBase {
4
		private $cache = [];
5
		private $compiledCache = [];
6
7 9
		private function getStorageLayer($path) {
8 9
			global $AR;
9 9
			if (isset($AR->templateStore)) {
10
				$layers = array_keys($AR->templateStore);
11
				// fallback
12
				$layer = array_reduce($layers, function($carry, $item) use ($path) {
13
					if(strpos($path, $item) === 0) {
14
						// item is a prefix of item
15
						if(!isset($carry) || (strlen($carry) < strlen($item) )) {
16
							// item is more specific
17
							$carry = $item;
18
						}
19
					}
20
					return $carry;
21
				}, null);
22
				if(isset($layer)) {
23
					$config =  $AR->templateStore[$layer];
24
					$classname = 'ar_template_' . $config['driver'];
25
					return new $classname($layer, $config);
26
				}
27
			}
28 9
			return new ar_template_filestore('/',[]);
0 ignored issues
show
Unused Code introduced by
The call to ar_template_filestore::__construct() has too many arguments starting with '/'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
29
		}
30
31
		public function get($path, $name){
32
			if(!isset($this->compiledCache[$path][$name])) {
33
				$this->compiledCache[$path][$name] = self::getStorageLayer($path)->get($path, $name);
34
			}
35
			return $this->compiledCache[$path][$name];
36
		}
37
38
		public function save($path, $name, $template, $local=null, $private=null) {
39
			return self::getStorageLayer($path)->save($path, $name, $template, $local, $private);
40
		}
41
42
		public function load($path, $name) {
43
			return self::getStorageLayer($path)->load($path, $name);
44
		}
45
46 15
		public function ls($path) {
47 15
			if (!isset($this->cache[$path])){
48 8
				$this->cache[$path] = self::getStorageLayer($path)->ls($path);
49 8
			}
50 15
			return $this->cache[$path];
51
		}
52
53
		public function rm($path, $name){
54
			return self::getStorageLayer($path)->rm($path, $name);
55
		}
56
57 3
		public function exists($path, $name) {
58 3
			return self::getStorageLayer($path)->exists($path, $name);
59
		}
60
61
		public function compile($path, $name) {
62
			return self::getStorageLayer($path)->compile($path, $name);
63
		}
64
	}
65