Completed
Branch 0.3.0 (b16461)
by Anton
04:03
created

Range   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 41
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 2
A exists() 0 4 1
A validate() 0 6 2
A get() 0 4 1
A array() 0 4 1
1
<?php
2
3
namespace {
4
5
	abstract class Range {
6
7
		protected static $range = [];
8
9
		# Load range
10
11
		protected static function init(string $file_name) {
12
13
			if (is_array($range = Explorer::php($file_name))) static::$range = $range;
14
		}
15
16
		# Check if item exists
17
18
		public static function exists($key) {
19
20
			return isset(static::$range[$key]);
21
		}
22
23
		# Validate key
24
25
		public static function validate($key) {
26
27
			$keys = array_keys(static::$range);
28
29
			return ((false !== ($key = array_search($key, $keys))) ? $keys[$key] : false);
30
		}
31
32
		# Get item by key
33
34
		public static function get($key) {
35
36
			return (static::$range[$key] ?? false);
37
		}
38
39
		# Get range array
40
41
		public static function array() {
42
43
			return static::$range;
44
		}
45
	}
46
}
47