Range   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 4 2
A get() 0 4 2
A getRange() 0 4 1
1
<?php
2
3
/**
4
 * @package Cadmium\System\Utils
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Utils {
11
12
	use Language;
13
14
	abstract class Range extends \Range {
15
16
		/**
17
		 * Translate a value accordingly to an active language
18
		 *
19
		 * @return string|mixed : the translated value or the raw value if the phrase does not exist
20
		 */
21
22
		private static function translate($value) {
23
24
			return ((false !== ($translated = Language::get($value))) ? $translated : $value);
25
		}
26
27
		/**
28
		 * Get a translated item value by a key
29
		 *
30
		 * @return mixed|null : the value if the key exists, otherwise null
31
		 */
32
33
		public static function get($key) {
34
35
			return ((null !== ($value = parent::get($key))) ? self::translate($value) : null);
36
		}
37
38
		/**
39
		 * Get the translated range array
40
		 */
41
42
		public static function getRange() : array {
43
44
			return array_map('self::translate', parent::getRange());
45
		}
46
	}
47
}
48