Controller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 24 5
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\Settings;
13
14
	abstract class Controller {
15
16
		/**
17
		 * Invoker
18
		 *
19
		 * @return true|string|array : true on success, otherwise an error code, or an array of type [$param_name, $error_code],
20
		 *         where $param_name is a name of param that has triggered the error,
21
		 *         and $error_code is a language phrase related to the error
22
		 */
23
24
		public function __invoke(array $post) {
25
26
			# Define errors list
27
28
			$errors = [];
29
30
			$errors['system_url']       = 'SETTINGS_ERROR_SYSTEM_URL';
31
			$errors['system_email']     = 'SETTINGS_ERROR_SYSTEM_EMAIL';
32
33
			# Process post data
34
35
			foreach (Settings::setArray($post) as $name => $result) {
36
37
				if (!$result) return (isset($errors[$name]) ? [$name, $errors[$name]] : false);
38
			}
39
40
			# Save settings
41
42
			if (!Settings::save()) return 'SETTINGS_ERROR_SAVE';
43
44
			# ------------------------
45
46
			return true;
47
		}
48
	}
49
}
50