Completed
Push — master ( 3f79ab...6d3a78 )
by Nazar
04:26
created

core_options_common   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 52
ccs 0
cts 20
cp 0
rs 10
wmc 7
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A admin_core_options_apply() 0 6 2
A admin_core_options_common() 0 8 2
A admin_core_options_save() 0 6 2
A admin_core_options_cancel() 0 3 1
1
<?php
2
/**
3
 * @package    CleverStyle Framework
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2016, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\api\Controller\admin;
11
use
12
	cs\Config,
13
	cs\ExitException;
14
15
trait core_options_common {
16
	/**
17
	 * Apply mail settings
18
	 *
19
	 * @param \cs\Request $Request
20
	 * @param string[]    $options
21
	 *
22
	 * @throws ExitException
23
	 */
24
	protected static function admin_core_options_apply ($Request, $options) {
25
		static::admin_core_options_common($Request, $options);
26
		if (!Config::instance()->apply()) {
27
			throw new ExitException(500);
28
		}
29
	}
30
	/**
31
	 * @param \cs\Request $Request
32
	 * @param string[]    $options
33
	 *
34
	 * @throws ExitException
35
	 */
36
	protected static function admin_core_options_common ($Request, $options) {
37
		$data = $Request->data($options);
38
		if (!$data) {
39
			throw new ExitException(400);
40
		}
41
		$Config       = Config::instance();
42
		$Config->core = $data + $Config->core;
43
	}
44
	/**
45
	 * Save mail settings
46
	 *
47
	 * @param \cs\Request $Request
48
	 * @param string[]    $options
49
	 *
50
	 * @throws ExitException
51
	 */
52
	protected static function admin_core_options_save ($Request, $options) {
53
		static::admin_core_options_common($Request, $options);
54
		if (!Config::instance()->save()) {
55
			throw new ExitException(500);
56
		}
57
	}
58
	/**
59
	 * Cancel mail settings
60
	 *
61
	 * @throws ExitException
62
	 */
63
	protected static function admin_core_options_cancel () {
64
		Config::instance()->cancel();
65
	}
66
}
67