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

mail::admin_mail_settings_common()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 28
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 25
c 1
b 1
f 0
nc 2
nop 1
dl 0
loc 28
ccs 0
cts 26
cp 0
crap 12
rs 8.8571

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mail::admin_mail_save_settings() 0 3 1
A mail::admin_mail_cancel_settings() 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) 2015-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
	cs\Mail as System_mail;
15
16
trait mail {
17
	protected static $mail_options_keys = [
18
		'smtp',
19
		'smtp_host',
20
		'smtp_port',
21
		'smtp_secure',
22
		'smtp_auth',
23
		'smtp_user',
24
		'smtp_password',
25
		'mail_from',
26
		'mail_from_name',
27
		'mail_signature'
28
	];
29
	/**
30
	 * Get mail settings
31
	 */
32
	public static function admin_mail_get_settings () {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
33
		$Config = Config::instance();
34
		return $Config->core(static::$mail_options_keys) + [
35
			'applied' => $Config->cancel_available()
36
		];
37
	}
38
	/**
39
	 * Send test email to check if setup is correct
40
	 *
41
	 * @param \cs\Request $Request
42
	 *
43
	 * @throws ExitException
44
	 */
45
	public static function admin_mail_send_test_email ($Request) {
46
		$email = $Request->data('email');
47
		if (!$email) {
48
			throw new ExitException(400);
49
		}
50
		if (!System_mail::instance()->send_to($email, 'Email testing on '.Config::instance()->core['site_name'], 'Test email')) {
51
			throw new ExitException(500);
52
		}
53
	}
54
	/**
55
	 * Apply mail settings
56
	 *
57
	 * @param \cs\Request $Request
58
	 *
59
	 * @throws ExitException
60
	 */
61
	public static function admin_mail_apply_settings ($Request) {
62
		static::admin_core_options_apply($Request, static::$mail_options_keys);
63
	}
64
	/**
65
	 * Save mail settings
66
	 *
67
	 * @param \cs\Request $Request
68
	 *
69
	 * @throws ExitException
70
	 */
71
	public static function admin_mail_save_settings ($Request) {
72
		static::admin_core_options_save($Request, static::$mail_options_keys);
73
	}
74
	/**
75
	 * Cancel mail settings
76
	 *
77
	 * @throws ExitException
78
	 */
79
	public static function admin_mail_cancel_settings () {
80
		static::admin_core_options_cancel();
81
	}
82
}
83