about_server::admin_about_server_get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 54
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 44
nc 2
nop 0
dl 0
loc 54
rs 9.6716
c 0
b 0
f 0
ccs 0
cts 40
cp 0
crap 6

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
 * @license    0BSD
8
 */
9
namespace cs\modules\System\api\Controller\admin;
10
use
11
	cs\Core,
12
	cs\DB,
13
	cs\Language;
14
15
trait about_server {
16
	/**
17
	 * Get information about server
18
	 */
19
	public static function admin_about_server_get () {
20
		$Core = Core::instance();
21
		$L    = Language::prefix('system_filesize_');
22
		return [
23
			'operating_system' => php_uname('s').' '.php_uname('r').' '.php_uname('v'),
24
			'server_type'      => static::admin_about_server_get_server_api(),
25
			'available_ram'    => ini_get('memory_limit') < 0 ? false : format_filesize(
26
				str_replace(
0 ignored issues
show
Bug introduced by
str_replace(array('K', '...ni_get('memory_limit')) of type string is incompatible with the type integer expected by parameter $size of format_filesize(). ( Ignorable by Annotation )

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

26
				/** @scrutinizer ignore-type */ str_replace(
Loading history...
27
					['K', 'M', 'G'],
28
					[" $L->KiB", " $L->MiB", " $L->GiB"],
0 ignored issues
show
Bug Best Practice introduced by
The property KiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property MiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property GiB does not exist on cs\Language\Prefix. Since you implemented __get, consider adding a @property annotation.
Loading history...
29
					ini_get('memory_limit')
30
				)
31
			),
32
			'php_extensions'   => [
33
				'openssl'   => extension_loaded('openssl'),
34
				'curl'      => extension_loaded('curl'),
35
				'apc'       => extension_loaded('apc'),
36
				'apcu'      => extension_loaded('apcu'),
37
				'memcached' => extension_loaded('memcached')
38
			],
39
			'main_db'          => [
40
				'driver'  => $Core->db_driver,
41
				'version' => DB::instance()->db(0)->server(),
0 ignored issues
show
Bug introduced by
The method server() does not exist on cs\False_class. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

41
				'version' => DB::instance()->db(0)->/** @scrutinizer ignore-call */ server(),
Loading history...
42
				'host'    => $Core->db_host,
43
				'name'    => $Core->db_name,
44
				'prefix'  => $Core->db_prefix
45
			],
46
			'main_storage'     => [
47
				'driver' => $Core->storage_driver
48
			],
49
			'cache_driver'     => $Core->cache_driver,
50
			'free_disk_space'  => format_filesize(disk_free_space('./'), 2),
0 ignored issues
show
Bug introduced by
disk_free_space('./') of type false|double is incompatible with the type integer expected by parameter $size of format_filesize(). ( Ignorable by Annotation )

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

50
			'free_disk_space'  => format_filesize(/** @scrutinizer ignore-type */ disk_free_space('./'), 2),
Loading history...
51
			'php_ini'          => [
52
				'allow_file_uploads'     => (bool)ini_get('file_uploads'),
53
				'max_file_uploads'       => (int)ini_get('max_file_uploads'),
54
				'upload_size_limit'      => format_filesize(
55
					str_replace(
56
						['K', 'M', 'G'],
57
						[" $L->KiB", " $L->MiB", " $L->GiB"],
58
						ini_get('upload_max_filesize')
59
					)
60
				),
61
				'post_max_size'          => format_filesize(
62
					str_replace(
63
						['K', 'M', 'G'],
64
						[" $L->KiB", " $L->MiB", " $L->GiB"],
65
						ini_get('post_max_size')
66
					)
67
				),
68
				'max_execution_time'     => format_time(ini_get('max_execution_time')),
0 ignored issues
show
Bug introduced by
ini_get('max_execution_time') of type string is incompatible with the type integer expected by parameter $time of format_time(). ( Ignorable by Annotation )

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

68
				'max_execution_time'     => format_time(/** @scrutinizer ignore-type */ ini_get('max_execution_time')),
Loading history...
69
				'max_input_time'         => format_time(ini_get('max_input_time')),
70
				'default_socket_timeout' => format_time(ini_get('default_socket_timeout')),
71
				'allow_url_fopen'        => (bool)ini_get('allow_url_fopen'),
72
				'display_errors'         => (bool)ini_get('display_errors'),
73
			]
74
		];
75
	}
76
	/**
77
	 * Returns server type
78
	 *
79
	 * @return string
80
	 */
81
	static private function admin_about_server_get_server_api () {
82
		$server_software = $_SERVER['SERVER_SOFTWARE'] ?? '';
83
		$phpinfo         = ob_wrapper('phpinfo');
84
		if (stripos($server_software, 'apache') !== false) {
85
			preg_match(
86
				'/Apache[\-\/]([0-9\.\-]+)/',
87
				ob_wrapper('phpinfo'),
88
				$version
89
			);
90
			$return = "Apache $version[1]";
91
			if (stripos($phpinfo, 'mod_php') !== false) {
92
				$return .= ' + mod_php + PHP '.PHP_VERSION;
93
			}
94
			return $return;
95
		}
96
		if (stripos($server_software, 'nginx') !== false) {
97
			$return = 'Nginx '.explode('/', $server_software)[1];
98
			if (stripos($phpinfo, 'php-fpm') !== false) {
99
				$return .= ' + PHP-FPM '.PHP_VERSION;
100
			}
101
			return $return;
102
		}
103
		return $server_software;
104
	}
105
}
106