languages::admin_languages_get_settings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 5
cp 0
crap 2
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
13
trait languages {
14
	protected static $languages_options_keys = [
15
		'language',
16
		'active_languages',
17
		'multilingual'
18
	];
19
	/**
20
	 * Get languages settings
21
	 *
22
	 * @return array
23
	 */
24
	public static function admin_languages_get_settings () {
25
		$Config = Config::instance();
26
		return $Config->core(static::$languages_options_keys) + [
27
			'languages' => static::get_languages_array(),
28
			'applied'   => $Config->cancel_available()
29
		];
30
	}
31
	/**
32
	 * @return string[]
33
	 */
34
	protected static function get_languages_array () {
35
		$languages = array_unique(
36
			array_merge(
37
				_mb_substr(get_files_list(LANGUAGES, '/^.*?\.php$/i', 'f'), 0, -4) ?: [],
0 ignored issues
show
Bug introduced by
It seems like _mb_substr(get_files_lis...'f'), 0, -4) ?: array() can also be of type string; however, parameter $array1 of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

37
				/** @scrutinizer ignore-type */ _mb_substr(get_files_list(LANGUAGES, '/^.*?\.php$/i', 'f'), 0, -4) ?: [],
Loading history...
38
				_mb_substr(get_files_list(LANGUAGES, '/^.*?\.json$/i', 'f'), 0, -5) ?: []
0 ignored issues
show
Bug introduced by
It seems like _mb_substr(get_files_lis...'f'), 0, -5) ?: array() can also be of type string; however, parameter $array2 of array_merge() does only seem to accept null|array, maybe add an additional type check? ( Ignorable by Annotation )

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

38
				/** @scrutinizer ignore-type */ _mb_substr(get_files_list(LANGUAGES, '/^.*?\.json$/i', 'f'), 0, -5) ?: []
Loading history...
39
			)
40
		);
41
		asort($languages);
42
		return $languages;
43
	}
44
	/**
45
	 * Apply language settings
46
	 *
47
	 * @param \cs\Request $Request
48
	 *
49
	 * @throws \cs\ExitException
50
	 */
51
	public static function admin_languages_apply_settings ($Request) {
52
		static::admin_core_options_apply($Request, static::$languages_options_keys);
53
	}
54
	/**
55
	 * Save language settings
56
	 *
57
	 * @param \cs\Request $Request
58
	 *
59
	 * @throws \cs\ExitException
60
	 */
61
	public static function admin_languages_save_settings ($Request) {
62
		static::admin_core_options_save($Request, static::$languages_options_keys);
63
	}
64
	/**
65
	 * Cancel language settings
66
	 *
67
	 * @throws \cs\ExitException
68
	 */
69
	public static function admin_languages_cancel_settings () {
70
		static::admin_core_options_cancel();
71
	}
72
}
73