Completed
Push — master ( cb33fb...bc1d9b )
by Nazar
13:14
created

about_server::admin_about_server_get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 57
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 45
nc 2
nop 0
dl 0
loc 57
ccs 0
cts 40
cp 0
crap 6
rs 9.6818
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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-2017, Nazar Mokrynskyi
8
 * @license    MIT License, see license.txt
9
 */
10
namespace cs\modules\System\api\Controller\admin;
11
use
12
	cs\Core,
13
	cs\DB,
14
	cs\Language;
15
16
trait about_server {
17
	/**
18
	 * Get information about server
19
	 */
20
	public static function admin_about_server_get () {
21
		$Core = Core::instance();
22
		$L    = Language::prefix('system_filesize_');
23
		return [
24
			'operating_system' => php_uname('s').' '.php_uname('r').' '.php_uname('v'),
25
			'server_type'      => static::admin_about_server_get_server_api(),
26
			'available_ram'    => ini_get('memory_limit') < 0 ? false : format_filesize(
27
				str_replace(
28
					['K', 'M', 'G'],
29
					[" $L->KiB", " $L->MiB", " $L->GiB"],
30
					ini_get('memory_limit')
31
				)
32
			),
33
			'php_extensions'   => [
34
				'openssl'   => extension_loaded('openssl'),
35
				'curl'      => extension_loaded('curl'),
36
				'apc'       => extension_loaded('apc'),
37
				'apcu'      => extension_loaded('apcu'),
38
				'memcached' => extension_loaded('memcached')
39
			],
40
			'main_db'          => [
41
				'driver'  => $Core->db_driver,
42
				'version' => DB::instance()->db(0)->server(),
43
				'host'    => $Core->db_host,
44
				'name'    => $Core->db_name,
45
				'prefix'  => $Core->db_prefix
46
			],
47
			'main_storage'     => [
48
				'driver' => $Core->storage_driver
49
			],
50
			'cache_driver'     => $Core->cache_driver,
51
			'free_disk_space'  => format_filesize(disk_free_space('./'), 2),
52
			'php_ini'          => [
53
				'allow_file_uploads'     => (bool)ini_get('file_uploads'),
54
				'max_file_uploads'       => (int)ini_get('max_file_uploads'),
55
				'upload_size_limit'      => format_filesize(
56
					str_replace(
57
						['K', 'M', 'G'],
58
						[" $L->KiB", " $L->MiB", " $L->GiB"],
59
						ini_get('upload_max_filesize')
60
					)
61
				),
62
				'post_max_size'          => format_filesize(
63
					str_replace(
64
						['K', 'M', 'G'],
65
						[" $L->KiB", " $L->MiB", " $L->GiB"],
66
						ini_get('post_max_size')
67
					)
68
				),
69
				'max_execution_time'     => format_time(ini_get('max_execution_time')),
70
				'max_input_time'         => format_time(ini_get('max_input_time')),
71
				'default_socket_timeout' => format_time(ini_get('default_socket_timeout')),
72
				'allow_url_fopen'        => (bool)ini_get('allow_url_fopen'),
73
				'display_errors'         => (bool)ini_get('display_errors'),
74
			]
75
		];
76
	}
77
	/**
78
	 * Returns server type
79
	 *
80
	 * @return string
81
	 */
82
	static private function admin_about_server_get_server_api () {
83
		$server_software = $_SERVER['SERVER_SOFTWARE'] ?? '';
84
		$phpinfo         = ob_wrapper('phpinfo');
85
		if (stripos($server_software, 'apache') !== false) {
86
			preg_match(
87
				'/Apache[\-\/]([0-9\.\-]+)/',
88
				ob_wrapper('phpinfo'),
89
				$version
90
			);
91
			$return = "Apache $version[1]";
92
			if (stripos($phpinfo, 'mod_php') !== false) {
93
				$return .= ' + mod_php + PHP '.PHP_VERSION;
94
			}
95
			return $return;
96
		}
97
		if (stripos($server_software, 'nginx') !== false) {
98
			$return = 'Nginx '.explode('/', $server_software)[1];
99
			if (stripos($phpinfo, 'php-fpm') !== false) {
100
				$return .= ' + PHP-FPM '.PHP_VERSION;
101
			}
102
			return $return;
103
		}
104
		return $server_software;
105
	}
106
}
107