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

ar_template_filestore   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 76.81%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 105
rs 10
c 2
b 0
f 0
ccs 53
cts 69
cp 0.7681
wmc 19
lcom 1
cbo 2

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilestore() 0 10 2
A pathToId() 0 10 2
A getConfig() 0 4 1
A get() 0 8 1
A save() 0 3 1
A load() 0 6 1
C ls() 0 33 8
A rm() 0 8 1
A exists() 0 8 1
A compile() 0 3 1
1
<?php
2
3
	class ar_template_filestore extends arBase {
4
5 36
		private function getFilestore() {
6 36
			$context = ar::context()->getObject();
7 36
			if(isset($context)) {
8 36
				$templates = $context->store->get_filestore("templates");
9 27
			} else {
10
				global $store;
11
				$templates = $store->get_filestore("templates");
12
			}
13 36
			return $templates;
14
		}
15
16 36
		private function pathToId($path) {
17 36
			$context = ar::context()->getObject();
18
19 36
			if($context->path == $path) {
20 36
				$result = $context->id;
21 27
			} else {
22
				$result = $context->loadConfig($path)->id;
23
			}
24 36
			return $result;
25
		}
26
27 28
		private function getConfig($path) {
28 28
			$context = ar::context()->getObject();
29 28
			return $context->loadConfig($path);
30
		}
31
32 12
		public function get($path, $name){
33 12
			$fs = $this->getfilestore();
34 12
			$id = $this->pathtoid($path);
35
36
			return (
37 12
				$fs->import($id, $name) 
38 9
			);
39
		}
40
41
		public function save($path, $name, $template, $local=null, $private=null) {
0 ignored issues
show
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $template is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $local is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $private is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
			return false;
43
		}
44
45
		public function load($path, $name) {
46
			$fs = $this->getfilestore();
47
			$id = $this->pathtoid($path);
48
49
			return $fs->read($id, $name . '.pinp');
50
		}
51
52 28
		public function ls($path) {
53 28
			$result = [];
54 28
			$fs = $this->getFilestore();
0 ignored issues
show
Unused Code introduced by
$fs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55 28
			$id = $this->pathToId($path);
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
56
57 28
			$config = $this->getConfig($path);
58
59 28
			$templates = $config->pinpTemplates;
60 28
			if (isset($templates)) foreach($templates as $type => $names) {
61 4
				if (isset($names)) foreach($names as $name => $languages) {
62 4
					if (isset($languages)) foreach($languages as $language => $id ) {
63 4
						$tempname = sprintf("%s.%s.%s",$type,$name,$language);
64 4
						list($maintype,$subtype) = explode('.', $type, 2);
65 4
						if(!isset($result[$name])) {
66 4
							$result[$name] = [];
67 3
						}
68 4
						$result[$name][] = [
69 4
							'id'       => $config->id,
70 4
							'path'     => $path,
71 4
							'type'     => $maintype,
72 4
							'subtype'  => $subtype,
73 4
							'name'     => $name,
74 4
							'filename' => $tempname,
75 4
							'language' => $language,
76 4
							'private'  => isset($config->privatetemplates[$type][$name]),
77 4
							'local'    => !isset($config->localTemplates[$type][$name][$language]),
78
						];
79 3
					}
80 3
				}
81 21
			}
82 28
			return $result;
83
84
		}
85
86
		public function rm($path, $name){
87
			$fs = $this->getfilestore();
88
			$id = $this->pathtoid($path);
89
90
			return (
91
				$fs->remove($id, $name) 
92
			);
93
		}
94
95 12
		public function exists($path, $name) {
96 12
			$fs = $this->getFilestore();
97 12
			$id = $this->pathToId($path);
98
99
			return (
100 12
				$fs->exists($id, $name . '.inc') 
101 9
			);
102
		}
103
104
		public function compile($path, $name) {
0 ignored issues
show
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
105
			// FIXME
0 ignored issues
show
Coding Style introduced by
Comment refers to a FIXME task
Loading history...
106
		}
107
	}
108