Completed
Push — master ( 71820b...0e2343 )
by Nazar
04:46
created

about_server::admin_about_server_get()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 57
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 57
rs 8.7433
cc 5
eloc 44
nc 1
nop 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 CMS
4
 * @subpackage System module
5
 * @category   modules
6
 * @author     Nazar Mokrynskyi <[email protected]>
7
 * @copyright  Copyright (c) 2015, 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
	cs\Page;
16
trait about_server {
17
	/**
18
	 * Get information about server
19
	 */
20
	static function admin_about_server_get () {
21
		$Core = Core::instance();
22
		$L    = Language::instance();
23
		$hhvm = defined('HHVM_VERSION');
24
		Page::instance()->json(
25
			[
26
				'operating_system' => php_uname('s').' '.php_uname('r').' '.php_uname('v'),
27
				'server_type'      => static::admin_about_server_get_server_api(),
28
				'available_ram'    => $hhvm ? '' : str_replace(
29
					['K', 'M', 'G'],
30
					[" $L->KB", " $L->MB", " $L->GB"],
31
					ini_get('memory_limit')
32
				),
33
				'php_extensions'   => [
34
					'openssl'   => extension_loaded('openssl'),
35
					'curl'      => extension_loaded('curl'),
36
					'apcu'      => extension_loaded('apcu'),
37
					'memcached' => extension_loaded('memcached')
38
				],
39
				'main_db'          => [
40
					'type'    => $Core->db_type,
41
					'version' => DB::instance()->server(),
1 ignored issue
show
Documentation Bug introduced by
The method server does not exist on object<cs\DB>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42
					'host'    => $Core->db_host,
43
					'name'    => $Core->db_name,
44
					'prefix'  => $Core->db_prefix
45
				],
46
				'main_storage'     => [
47
					'type' => $Core->storage_type
48
				],
49
				'cache_engine'     => $Core->cache_engine,
50
				'free_disk_space'  => format_filesize(disk_free_space('./'), 2),
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->KB", " $L->MB", " $L->GB"],
58
							ini_get('upload_max_filesize')
59
						)
60
					),
61
					'post_max_size'          => format_filesize(
62
						str_replace(
63
							['K', 'M', 'G'],
64
							[" $L->KB", " $L->MB", " $L->GB"],
65
							ini_get('post_max_size')
66
						)
67
					),
68
					'max_execution_time'     => $hhvm ? '' : format_time(ini_get('max_execution_time')),
69
					'max_input_time'         => $hhvm ? '' : format_time(ini_get('max_input_time')),
70
					'default_socket_timeout' => $hhvm ? '' : 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
	/**
78
	 * Returns server type
79
	 *
80
	 * @return string
81
	 */
82
	static private function admin_about_server_get_server_api () {
83
		$phpinfo = ob_wrapper('phpinfo');
84
		if (stripos($_SERVER['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
		} elseif (stripos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) {
96
			$return = 'Nginx '.explode('/', $_SERVER['SERVER_SOFTWARE'])[1];
97
			if (stripos($phpinfo, 'php-fpm') !== false) {
98
				$return .= ' + PHP-FPM '.PHP_VERSION;
99
			} elseif (defined('HHVM_VERSION')) {
100
				$return .= ' + HHVM '.HHVM_VERSION;
101
			}
102
			return $return;
103
		} elseif (isset($_SERVER['SERVER_SOFTWARE'])) {
104
			return $_SERVER['SERVER_SOFTWARE'];
105
		} else {
106
			return '';
107
		}
108
	}
109
}
110