Passed
Pull Request — master (#11)
by Anton
03:24
created

Loader   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 2
dl 0
loc 42
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
B getItem() 0 14 5
A dirName() 0 4 1
A items() 0 4 2
A exists() 0 4 1
1
<?php
2
3
namespace Modules\Extend\Utils {
4
5
	use Modules\Extend, Utils\Schema, Arr, JSON;
6
7
	abstract class Loader {
8
9
		protected $dir_name = '', $items = [];
10
11
		# Get item
12
13
		protected function getItem(string $name) {
14
15
			$file_name = ($this->dir_name . $name . '/Config.json');
16
17
			if (null === ($data = JSON::load($file_name))) return null;
18
19
			if (null === ($data = Schema::get(static::$schema_prototype)->validate($data))) return null;
20
21
			if (!(static::$extension_class::valid($data['name']) && ($data['name'] === $name))) return null;
22
23
			# ------------------------
24
25
			return $data;
26
		}
27
28
		# Return directory name
29
30
		public function dirName() {
31
32
			return $this->dir_name;
33
		}
34
35
		# Return items
36
37
		public function items(bool $plain = false) {
38
39
			return ($plain ? array_column($this->items, 'title', 'name') : $this->items);
40
		}
41
42
		# Check if item exists
43
44
		public function exists(string $name) {
45
46
			return isset($this->items[$name]);
47
		}
48
	}
49
}
50