Conditions | 17 |
Paths | 48 |
Total Lines | 87 |
Code Lines | 61 |
Lines | 36 |
Ratio | 41.38 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
12 | function phpxmlrpc_verify_compat($mode = 'client') |
||
13 | { |
||
14 | $tests = array(); |
||
15 | |||
16 | if ($mode == 'server') { |
||
17 | // test for php version |
||
18 | $ver = phpversion(); |
||
19 | $tests['php_version'] = array(); |
||
20 | $tests['php_version']['description'] = 'PHP version found: ' . $ver . ".\n\n"; |
||
21 | View Code Duplication | if (version_compare($ver, '5.3.0') < 0) { |
|
22 | $tests['php_version']['status'] = 0; |
||
23 | $tests['php_version']['description'] .= 'This version of PHP is not compatible with this release of the PHP XMLRPC library. Please upgrade to php 5.1.0 or later'; |
||
24 | } else { |
||
25 | $tests['php_version']['status'] = 2; |
||
26 | $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library'; |
||
27 | } |
||
28 | |||
29 | // test for zlib |
||
30 | $tests['zlib'] = array(); |
||
31 | View Code Duplication | if (!function_exists('gzinflate')) { |
|
32 | $tests['zlib']['status'] = 0; |
||
33 | $tests['zlib']['description'] = "The zlib extension is not enabled.\n\nYou will not be able to receive compressed requests or send compressed responses, unless using the cURL library (for 'HTTPS' and 'HTTP 1.1' connections)"; |
||
34 | } else { |
||
35 | $tests['zlib']['status'] = 2; |
||
36 | $tests['zlib']['description'] = "The zlib extension is enabled.\n\nYou will be able to receive compressed requests and send compressed responses for the 'HTTP' protocol"; |
||
37 | } |
||
38 | |||
39 | // test for dispaly of php errors in xml reponse |
||
40 | if (ini_get('display_errors')) { |
||
41 | if (intval(ini_get('error_reporting')) && E_NOTICE) { |
||
42 | $tests['display_errors']['status'] = 1; |
||
43 | $tests['display_errors']['description'] = "Error reporting level includes E_NOTICE errors, and display_errors is set to ON.\n\nAny error, warning or notice raised while executing php code exposed as xmlrpc method will result in an invalid xmlrpc response"; |
||
44 | } else { |
||
45 | $tests['display_errors']['status'] = 1; |
||
46 | $tests['display_errors']['description'] = "display_errors is set to ON.\n\nAny error raised while executing php code exposed as xmlrpc method will result in an invalid xmlrpc response"; |
||
47 | } |
||
48 | } |
||
49 | } else { |
||
50 | |||
51 | // test for php version |
||
52 | $ver = phpversion(); |
||
53 | $tests['php_version'] = array(); |
||
54 | $tests['php_version']['description'] = 'PHP version found: ' . $ver . ".\n\n"; |
||
55 | View Code Duplication | if (version_compare($ver, '5.3.0') < 0) { |
|
56 | $tests['php_version']['status'] = 0; |
||
57 | $tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 5.1.0 or later'; |
||
58 | } else { |
||
59 | $tests['php_version']['status'] = 2; |
||
60 | $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library'; |
||
61 | } |
||
62 | |||
63 | // test for zlib |
||
64 | $tests['zlib'] = array(); |
||
65 | View Code Duplication | if (!function_exists('gzinflate')) { |
|
66 | $tests['zlib']['status'] = 0; |
||
67 | $tests['zlib']['description'] = "The zlib extension is not enabled.\n\nYou will not be able to send compressed requests or receive compressed responses, unless using the cURL library (for 'HTTPS' and 'HTTP 1.1' connections)"; |
||
68 | } else { |
||
69 | $tests['zlib']['status'] = 2; |
||
70 | $tests['zlib']['description'] = "The zlib extension is enabled.\n\nYou will be able to send compressed requests and receive compressed responses for the 'HTTP' protocol"; |
||
71 | } |
||
72 | |||
73 | // test for CURL |
||
74 | $tests['curl'] = array(); |
||
75 | if (!extension_loaded('curl')) { |
||
76 | $tests['curl']['status'] = 0; |
||
77 | $tests['curl']['description'] = "The cURL extension is not enabled.\n\nYou will not be able to send and receive messages using 'HTTPS' and 'HTTP 1.1' protocols"; |
||
78 | } else { |
||
79 | $info = curl_version(); |
||
80 | $tests['curl']['status'] = 2; |
||
81 | $tests['curl']['description'] = "The cURL extension is enabled.\n\nYou will be able to send and receive messages using 'HTTPS' and 'HTTP 1.1' protocols"; |
||
82 | if (version_compare($ver, '4.3.8') < 0) { |
||
83 | $tests['curl']['status'] = 1; |
||
84 | $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support keep-alives"; |
||
85 | } |
||
86 | View Code Duplication | if (!((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version']))) { |
|
87 | $tests['curl']['status'] = 1; |
||
88 | $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages"; |
||
89 | } |
||
90 | View Code Duplication | if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version']))) { |
|
91 | $tests['curl']['status'] = 1; |
||
92 | $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support HTTPS connections"; |
||
93 | } |
||
94 | } |
||
95 | } |
||
96 | |||
97 | return $tests; |
||
98 | } |
||
99 | |||
194 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.