Dataset::__construct()   C
last analyzed

Complexity

Conditions 12
Paths 1

Size

Total Lines 100
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 5.034
c 0
b 0
f 0
cc 12
eloc 29
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
/**
4
 * @package Cadmium\System\Modules\Settings
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Settings\Utils {
11
12
	use Modules\Extend, Utils\Range, Utils\Validate, Geo\Timezone, Request;
13
14
	class Dataset extends \Dataset {
15
16
		/**
17
		 * Get default system url
18
		 */
19
20
		private function getSystemUrl() : string {
21
22
			if (empty($_SERVER['HTTP_HOST'])) return CONFIG_SYSTEM_URL;
23
24
			return ((Request::isSecure() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']);
25
		}
26
27
		/**
28
		 * Get default system email
29
		 */
30
31
		private function getSystemEmail() : string {
32
33
			if (empty($_SERVER['HTTP_HOST'])) return CONFIG_SYSTEM_EMAIL;
34
35
			return ('admin@' . $_SERVER['HTTP_HOST']);
36
		}
37
38
		/**
39
		 * Constructor
40
		 */
41
42
		public function __construct() {
43
44
			# Site language
45
46
			$this->addParam('site_language', CONFIG_SITE_LANGUAGE, function (string $name) {
47
48
				return ((false !== ($name = Extend\Languages::validate($name))) ? $name : null);
49
			});
50
51
			# Site template
52
53
			$this->addParam('site_template', CONFIG_SITE_TEMPLATE, function (string $name) {
54
55
				return ((false !== ($name = Extend\Templates::validate($name))) ? $name : null);
56
			});
57
58
			# Site title
59
60
			$this->addParam('site_title', CONFIG_SITE_TITLE, function (string $title) {
61
62
				return (('' !== $title) ? $title : null);
63
			});
64
65
			# Site slogan
66
67
			$this->addParam('site_slogan', CONFIG_SITE_SLOGAN, function (string $slogan) {
68
69
				return $slogan;
70
			});
71
72
			# Site status
73
74
			$this->addParam('site_status', CONFIG_SITE_STATUS, function (int $status) {
75
76
				return ((false !== ($status = Range\Status::validate($status))) ? $status : null);
77
			});
78
79
			# Site description
80
81
			$this->addParam('site_description', CONFIG_SITE_DESCRIPTION, function (string $description) {
82
83
				return $description;
84
			});
85
86
			# Site keywords
87
88
			$this->addParam('site_keywords', CONFIG_SITE_KEYWORDS, function (string $keywords) {
89
90
				return $keywords;
91
			});
92
93
			# System url
94
95
			$this->addParam('system_url', $this->getSystemUrl(), function (string $url) {
96
97
				return ((false !== ($url = Validate::url($url))) ? $url : null);
98
			});
99
100
			# System email
101
102
			$this->addParam('system_email', $this->getSystemEmail(), function (string $email) {
103
104
				return ((false !== ($email = Validate::email($email))) ? $email : null);
105
			});
106
107
			# System timezone
108
109
			$this->addParam('system_timezone', CONFIG_SYSTEM_TIMEZONE, function (string $timezone) {
110
111
				return ((false !== ($timezone = Timezone::validate($timezone))) ? $timezone : null);
112
			});
113
114
			# Admin language
115
116
			$this->addParam('admin_language', CONFIG_ADMIN_LANGUAGE, function (string $name) {
117
118
				return ((false !== ($name = Extend\Languages::validate($name))) ? $name : null);
119
			});
120
121
			# Admin template
122
123
			$this->addParam('admin_template', CONFIG_ADMIN_TEMPLATE, function (string $name) {
124
125
				return ((false !== ($name = Extend\Templates::validate($name))) ? $name : null);
126
			});
127
128
			# Admin display entities
129
130
			$this->addParam('admin_display_entities', CONFIG_ADMIN_DISPLAY_ENTITIES, function (int $display) {
131
132
				return ((false !== ($display = Range\Display\Entities::validate($display))) ? $display : null);
133
			});
134
135
			# Admin display files
136
137
			$this->addParam('admin_display_files', CONFIG_ADMIN_DISPLAY_FILES, function (int $display) {
138
139
				return ((false !== ($display = Range\Display\Files::validate($display))) ? $display : null);
140
			});
141
		}
142
	}
143
}
144