Completed
Push — php7.2-travis ( 46fda5...100f27 )
by
unknown
249:00 queued 239:17
created

ar_template_filestore::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1.0233

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
ccs 5
cts 7
cp 0.7143
crap 1.0233
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
	class ar_template_filestore extends arBase {
4
5 9
		private function getFilestore() {
6 9
			$context = ar::context()->getObject();
7 9
			if(isset($context)) {
8 9
				$templates = $context->store->get_filestore("templates");
9 9
			} else {
10
				global $store;
11
				$templates = $store->get_filestore("templates");
12
			}
13 9
			return $templates;
14
		}
15
16 9
		private function pathToId($path) {
17 9
			$context = ar::context()->getObject();
18
19 9
			if($context->path == $path) {
20 9
				$result = $context->id;
21 9
			} else {
22
				$result = $context->loadConfig($path)->id;
23
			}
24 9
			return $result;
25
		}
26
27 7
		private function getConfig($path) {
28 7
			$context = ar::context()->getObject();
29 7
			return $context->loadConfig($path);
30
		}
31
32 2
		public function get($path, $name){
33 2
			$fs = $this->getfilestore();
34 2
			$id = $this->pathtoid($path);
35
36
			return (
37 2
				$fs->import($id, $name) 
38 2
			);
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 7
		public function ls($path) {
53 7
			$result = [];
54 7
			$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 7
			$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 7
			$config = $this->getConfig($path);
58
59 7
			$templates = $config->pinpTemplates;
60 7
			if (isset($templates)) foreach($templates as $type => $names) {
61 1
				if (isset($names)) foreach($names as $name => $languages) {
62 1
					if (isset($languages)) foreach($languages as $language => $id ) {
63 1
						$tempname = sprintf("%s.%s.%s",$type,$name,$language);
64 1
						list($maintype,$subtype) = explode('.', $type, 2);
65 1
						if(!isset($result[$name])) {
66 1
							$result[$name] = [];
67 1
						}
68 1
						$result[$name][] = [
69 1
							'id'       => $config->id,
70 1
							'path'     => $path,
71 1
							'type'     => $maintype,
72 1
							'subtype'  => $subtype,
73 1
							'name'     => $name,
74 1
							'filename' => $tempname,
75 1
							'language' => $language,
76 1
							'private'  => isset($config->privatetemplates[$type][$name]),
77 1
							'local'    => !isset($config->localTemplates[$type][$name][$language]),
78
						];
79 1
					}
80 1
				}
81 7
			}
82 7
			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 3
		public function exists($path, $name) {
96 3
			$fs = $this->getFilestore();
97 3
			$id = $this->pathToId($path);
98
99
			return (
100 3
				$fs->exists($id, $name . '.inc') 
101 3
			);
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