Completed
Push — master ( 7665c8...9af7b9 )
by Robbert
61:21 queued 52:46
created

ar_template   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 37.14%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
dl 0
loc 58
rs 10
c 3
b 0
f 2
ccs 13
cts 35
cp 0.3714
wmc 14
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
B getStorageLayer() 0 23 6
A get() 0 3 1
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
1
<?php
2
3
	class ar_template extends arBase {
4
		private $cache = [];
5
6 36
		private function getStorageLayer($path) {
7 36
			global $AR;
8 36
			if (isset($AR->templateStore)) {
9
				$layers = array_keys($AR->templateStore);
10
				// fallback
11
				$layer = array_reduce($layers, function($carry, $item) use ($path) {
12
					if(strpos($path, $item) === 0) {
13
						// item is a prefix of item
14
						if(!isset($carry) || (strlen($carry) < strlen($item) )) {
15
							// item is more specific
16
							$carry = $item;
17
						}
18
					}
19
					return $carry;
20
				}, null);
21
				if(isset($layer)) {
22
					$config =  $AR->templateStore[$layer];
23
					$classname = 'ar_template_' . $config['driver'];
24
					return new $classname($layer, $config);
25
				}
26
			}
27 36
			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...
28
		}
29
30 12
		public function get($path, $name){
31 12
			return self::getStorageLayer($path)->get($path, $name);
32
		}
33
34
		public function save($path, $name, $template, $local=null, $private=null) {
35
			return self::getStorageLayer($path)->save($path, $name, $template, $local, $private);
36
		}
37
38
		public function load($path, $name) {
39
			return self::getStorageLayer($path)->load($path, $name);
40
		}
41
42 60
		public function ls($path) {
43 60
			if (!isset($this->cache[$path])){
44 28
				$this->cache[$path] = self::getStorageLayer($path)->ls($path);
45 21
			}
46 60
			return $this->cache[$path];
47
		}
48
49
		public function rm($path, $name){
50
			return self::getStorageLayer($path)->rm($path, $name);
51
		}
52
53 12
		public function exists($path, $name) {
54 12
			return self::getStorageLayer($path)->exists($path, $name);
55
		}
56
57
		public function compile($path, $name) {
58
			return self::getStorageLayer($path)->compile($path, $name);
59
		}
60
	}
61