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

languages::admin_languages_settings_common()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 2
nop 1
dl 0
loc 15
ccs 0
cts 12
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A languages::admin_languages_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
14
trait languages {
15
	protected static $languages_options_keys = [
16
		'language',
17
		'active_languages',
18
		'multilingual'
19
	];
20
	/**
21
	 * Get languages settings
22
	 */
23
	public static function admin_languages_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...
24
		$Config = Config::instance();
25
		return $Config->core(static::$languages_options_keys) + [
26
			'languages' => static::get_languages_array(),
27
			'applied'   => $Config->cancel_available()
28
		];
29
	}
30
	/**
31
	 * @return string[]
32
	 */
33
	protected static function get_languages_array () {
34
		$languages = array_unique(
35
			array_merge(
36
				_mb_substr(get_files_list(LANGUAGES, '/^.*?\.php$/i', 'f'), 0, -4) ?: [],
37
				_mb_substr(get_files_list(LANGUAGES, '/^.*?\.json$/i', 'f'), 0, -5) ?: []
38
			)
39
		);
40
		asort($languages);
41
		return $languages;
42
	}
43
	/**
44
	 * Apply language settings
45
	 *
46
	 * @param \cs\Request $Request
47
	 *
48
	 * @throws \cs\ExitException
49
	 */
50
	public static function admin_languages_apply_settings ($Request) {
51
		static::admin_core_options_apply($Request, static::$languages_options_keys);
52
	}
53
	/**
54
	 * Save language settings
55
	 *
56
	 * @param \cs\Request $Request
57
	 *
58
	 * @throws \cs\ExitException
59
	 */
60
	public static function admin_languages_save_settings ($Request) {
61
		static::admin_core_options_save($Request, static::$languages_options_keys);
62
	}
63
	/**
64
	 * Cancel language settings
65
	 *
66
	 * @throws \cs\ExitException
67
	 */
68
	public static function admin_languages_cancel_settings () {
69
		static::admin_core_options_cancel();
70
	}
71
}
72