Passed
Push — master ( e0d6a2...2ec881 )
by Anton
05:25 queued 02:20
created

Controller::__invoke()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 24
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 8
nc 6
nop 1
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 string|array|true : an error code, or an array of type ['param name', 'error code'], or true on success
20
		 */
21
22
		public function __invoke(array $post) {
23
24
			# Define errors list
25
26
			$errors = [];
27
28
			$errors['system_url']       = 'SETTINGS_ERROR_SYSTEM_URL';
29
			$errors['system_email']     = 'SETTINGS_ERROR_SYSTEM_EMAIL';
30
31
			# Process post data
32
33
			foreach (Settings::setArray($post) as $name => $result) {
34
35
				if (!$result) return (isset($errors[$name]) ? [$name, $errors[$name]] : false);
36
			}
37
38
			# Save settings
39
40
			if (!Settings::save()) return 'SETTINGS_ERROR_SAVE';
41
42
			# ------------------------
43
44
			return true;
45
		}
46
	}
47
}
48