Passed
Push — master ( a357e7...195a07 )
by Anton
04:22 queued 01:11
created

Dataset::__construct()   C

Complexity

Conditions 10
Paths 1

Size

Total Lines 86
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 86
rs 5.3068
c 0
b 0
f 0
cc 10
eloc 25
nc 1
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Modules\Settings\Utils {
4
5
	use Modules\Extend, Utils\Range, Utils\Validate, Geo\Timezone, Request;
6
7
	class Dataset extends \Dataset {
8
9
		# Get system url
10
11
		private function getSystemUrl() {
12
13
			if (empty($host = getenv('HTTP_HOST'))) return;
14
15
			return ((Request::isSecure() ? 'https://' : 'http://') . $host);
16
		}
17
18
		# Get system email
19
20
		private function getSystemEmail() {
21
22
			if (empty($host = getenv('HTTP_HOST'))) return;
23
24
			return ('admin@' . $host);
25
		}
26
27
		# Constructor
28
29
		public function __construct() {
30
31
			# Admin language
32
33
			$this->addParam('admin_language', CONFIG_ADMIN_LANGUAGE_DEFAULT, function (string $name) {
34
35
				return ((false !== ($name = Extend\Languages::validate($name))) ? $name : null);
36
			});
37
38
			# Admin template
39
40
			$this->addParam('admin_template', CONFIG_ADMIN_TEMPLATE_DEFAULT, function (string $name) {
41
42
				return ((false !== ($name = Extend\Templates::validate($name))) ? $name : null);
43
			});
44
45
			# Site language
46
47
			$this->addParam('site_language', CONFIG_SITE_LANGUAGE_DEFAULT, function (string $name) {
48
49
				return ((false !== ($name = Extend\Languages::validate($name))) ? $name : null);
50
			});
51
52
			# Site template
53
54
			$this->addParam('site_template', CONFIG_SITE_TEMPLATE_DEFAULT, function (string $name) {
55
56
				return ((false !== ($name = Extend\Templates::validate($name))) ? $name : null);
57
			});
58
59
			# Site title
60
61
			$this->addParam('site_title', CONFIG_SITE_TITLE_DEFAULT, function (string $title) {
62
63
				return (('' !== $title) ? $title : null);
64
			});
65
66
			# Site slogan
67
68
			$this->addParam('site_slogan', CONFIG_SITE_SLOGAN_DEFAULT, function (string $slogan) {
69
70
				return $slogan;
71
			});
72
73
			# Site status
74
75
			$this->addParam('site_status', STATUS_ONLINE, function (string $status) {
76
77
				return ((false !== ($status = Range\Status::validate($status))) ? $status : null);
78
			});
79
80
			# Site description
81
82
			$this->addParam('site_description', '', function (string $description) {
83
84
				return $description;
85
			});
86
87
			# Site keywords
88
89
			$this->addParam('site_keywords', '', function (string $keywords) {
90
91
				return $keywords;
92
			});
93
94
			# System url
95
96
			$this->addParam('system_url', $this->getSystemUrl(), function (string $url) {
97
98
				return ((false !== ($url = Validate::url($url))) ? $url : null);
99
			});
100
101
			# System email
102
103
			$this->addParam('system_email', $this->getSystemEmail(), function (string $email) {
104
105
				return ((false !== ($email = Validate::email($email))) ? $email : null);
106
			});
107
108
			# System timezone
109
110
			$this->addParam('system_timezone', CONFIG_SYSTEM_TIMEZONE_DEFAULT, function (string $timezone) {
111
112
				return ((false !== ($timezone = Timezone::validate($timezone))) ? $timezone : null);
113
			});
114
		}
115
	}
116
}
117