Completed
Push — master ( 416cb1...222de5 )
by Anton
03:44
created

Map   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 4
A handler() 0 11 3
1
<?php
2
3
namespace Utils {
4
5
	use Explorer, Url;
6
7
	class Map {
8
9
		private $map = [];
10
11
		# Constructor
12
13
		public function __construct() {
14
15
			$file_name = (DIR_SYSTEM_DATA . 'Map.xml');
16
17
			if (false !== ($map_xml = Explorer::xml($file_name))) {
18
19
				foreach ($map_xml->item as $item) {
20
21
					$item = new Map\Item($item->path, $item->handler);
22
23
					if ($item->parsed()) $this->map[] = $item;
24
				}
25
			}
26
		}
27
28
		# Get handler by url
29
30
		public function handler(Url $url) {
31
32
			foreach ($this->map as $item) {
33
34
				if (false !== ($handler = $item->handler($url->path()))) return $handler;
35
			}
36
37
			# ------------------------
38
39
			return false;
40
		}
41
	}
42
}
43