mail   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
ccs 0
cts 19
cp 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A admin_mail_cancel_settings() 0 2 1
A admin_mail_send_test_email() 0 7 3
A admin_mail_apply_settings() 0 2 1
A admin_mail_get_settings() 0 4 1
A admin_mail_save_settings() 0 2 1
1
<?php
2
/**
3
 * @package    CleverStyle Framework
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @license    0BSD
8
 */
9
namespace cs\modules\System\api\Controller\admin;
10
use
11
	cs\Config,
12
	cs\ExitException,
13
	cs\Mail as System_mail;
14
15
trait mail {
16
	protected static $mail_options_keys = [
17
		'smtp',
18
		'smtp_host',
19
		'smtp_port',
20
		'smtp_secure',
21
		'smtp_auth',
22
		'smtp_user',
23
		'smtp_password',
24
		'mail_from',
25
		'mail_from_name',
26
		'mail_signature'
27
	];
28
	/**
29
	 * Get mail settings
30
	 *
31
	 * @return array
32
	 */
33
	public static function admin_mail_get_settings () {
34
		$Config = Config::instance();
35
		return $Config->core(static::$mail_options_keys) + [
36
			'applied' => $Config->cancel_available()
37
		];
38
	}
39
	/**
40
	 * Send test email to check if setup is correct
41
	 *
42
	 * @param \cs\Request $Request
43
	 *
44
	 * @throws ExitException
45
	 */
46
	public static function admin_mail_send_test_email ($Request) {
47
		$email = $Request->data('email');
0 ignored issues
show
Bug introduced by
'email' of type string is incompatible with the type array<mixed,string[]>|string[] expected by parameter $name of cs\Request::data(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
		$email = $Request->data(/** @scrutinizer ignore-type */ 'email');
Loading history...
48
		if (!$email) {
49
			throw new ExitException(400);
50
		}
51
		if (!System_mail::instance()->send_to($email, 'Email testing on '.Config::instance()->core['site_name'], 'Test email')) {
52
			throw new ExitException(500);
53
		}
54
	}
55
	/**
56
	 * Apply mail settings
57
	 *
58
	 * @param \cs\Request $Request
59
	 *
60
	 * @throws ExitException
61
	 */
62
	public static function admin_mail_apply_settings ($Request) {
63
		static::admin_core_options_apply($Request, static::$mail_options_keys);
64
	}
65
	/**
66
	 * Save mail settings
67
	 *
68
	 * @param \cs\Request $Request
69
	 *
70
	 * @throws ExitException
71
	 */
72
	public static function admin_mail_save_settings ($Request) {
73
		static::admin_core_options_save($Request, static::$mail_options_keys);
74
	}
75
	/**
76
	 * Cancel mail settings
77
	 *
78
	 * @throws ExitException
79
	 */
80
	public static function admin_mail_cancel_settings () {
81
		static::admin_core_options_cancel();
82
	}
83
}
84