phpxmlrpc_verify_compat()   C
last analyzed

Complexity

Conditions 17
Paths 48

Size

Total Lines 86
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 17
eloc 60
nc 48
nop 1
dl 0
loc 86
rs 5.2166
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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
 * Verify compatibility level of current php install with php-xmlrpc lib.
4
 *
5
 * @author Gaetano Giunta
6
 * @copyright (C) 2006-2025 G. Giunta
7
 * @license code licensed under the BSD License: see file license.txt
8
 *
9
 * @todo add a test for php output buffering?
10
 * @todo check for presence of specific curl options, such as fe. the HTTP2 ones
11
 * @todo check for presence of mbstring
12
 * @todo check for presence of the xmlrpc extension
13
 */
14
15
function phpxmlrpc_verify_compat($mode = 'client')
16
{
17
    $tests = array();
18
19
    if ($mode == 'server') {
20
        // test for php version
21
        $ver = phpversion();
22
        $tests['php_version'] = array();
23
        $tests['php_version']['description'] = 'PHP version found: ' . $ver . ".\n\n";
24
        if (version_compare($ver, '5.3.0') < 0) {
25
            $tests['php_version']['status'] = 0;
26
            $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';
27
        } else {
28
            $tests['php_version']['status'] = 2;
29
            $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
30
        }
31
32
        // test for zlib
33
        $tests['zlib'] = array();
34
        if (!function_exists('gzinflate')) {
35
            $tests['zlib']['status'] = 0;
36
            $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)";
37
        } else {
38
            $tests['zlib']['status'] = 2;
39
            $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";
40
        }
41
42
        // test for display of php errors in xml response
43
        if (ini_get('display_errors')) {
44
            if (intval(ini_get('error_reporting')) && E_NOTICE) {
45
                $tests['display_errors']['status'] = 1;
46
                $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";
47
            } else {
48
                $tests['display_errors']['status'] = 1;
49
                $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";
50
            }
51
        }
52
    } else {
53
54
        // test for php version
55
        $ver = phpversion();
56
        $tests['php_version'] = array();
57
        $tests['php_version']['description'] = 'PHP version found: ' . $ver . ".\n\n";
58
        if (version_compare($ver, '5.3.0') < 0) {
59
            $tests['php_version']['status'] = 0;
60
            $tests['php_version']['description'] .= 'This version of PHP is not compatible with the PHP XMLRPC library. Please upgrade to 5.1.0 or later';
61
        } else {
62
            $tests['php_version']['status'] = 2;
63
            $tests['php_version']['description'] .= 'This version of PHP is fully compatible with the PHP XMLRPC library';
64
        }
65
66
        // test for zlib
67
        $tests['zlib'] = array();
68
        if (!function_exists('gzinflate')) {
69
            $tests['zlib']['status'] = 0;
70
            $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)";
71
        } else {
72
            $tests['zlib']['status'] = 2;
73
            $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";
74
        }
75
76
        // test for CURL
77
        $tests['curl'] = array();
78
        if (!extension_loaded('curl')) {
79
            $tests['curl']['status'] = 0;
80
            $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";
81
        } else {
82
            $info = curl_version();
83
            $tests['curl']['status'] = 2;
84
            $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";
85
            if (version_compare($ver, '4.3.8') < 0) {
86
                $tests['curl']['status'] = 1;
87
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support keep-alives";
88
            }
89
            if (!((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version']))) {
0 ignored issues
show
introduced by
The condition is_string($info) is always false.
Loading history...
90
                $tests['curl']['status'] = 1;
91
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages";
92
            }
93
            if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version']))) {
94
                $tests['curl']['status'] = 1;
95
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support HTTPS connections";
96
            }
97
        }
98
    }
99
100
    return $tests;
101
}
102
103
?>
104
<!DOCTYPE html>
105
<html lang="en">
106
<head>
107
    <title>PHP XMLRPC compatibility assessment</title>
108
    <style>
109
        body, html {
110
            background-color: white;
111
            font-family: Arial, Verdana, Geneva, sans-serif;
112
            font-size: small;
113
        }
114
        table {
115
            border: 1px solid gray;
116
            padding: 0;
117
        }
118
        thead {
119
            background-color: silver;
120
            color: black;
121
        }
122
        td {
123
            margin: 0;
124
            padding: 0.5em;
125
        }
126
        tbody td {
127
            border-top: 1px solid gray;
128
        }
129
        .res0 {
130
            background-color: red;
131
            color: black;
132
            border-right: 1px solid gray;
133
        }
134
        .res1 {
135
            background-color: yellow;
136
            color: black;
137
            border-right: 1px solid gray;
138
        }
139
        .res2 {
140
            background-color: green;
141
            color: black;
142
            border-right: 1px solid gray;
143
        }
144
        .result {
145
            white-space: pre;
146
        }
147
    </style>
148
</head>
149
<body>
150
<h1>PHPXMLRPC compatibility assessment with the current PHP install</h1>
151
<h4>For phpxmlrpc version 4.0 or later</h4>
152
153
<h3>Server usage</h3>
154
<table>
155
    <thead>
156
    <tr>
157
        <td>Test</td>
158
        <td>Result</td>
159
    </tr>
160
    </thead>
161
    <tbody>
162
    <?php
163
    $res = phpxmlrpc_verify_compat('server');
164
    foreach ($res as $test => $result) {
165
        echo '<tr><td class="res' . $result['status'] . '">' . htmlspecialchars($test) . '</td><td class="result">' . htmlspecialchars($result['description']) . "</td></tr>\n";
166
    }
167
    ?>
168
    </tbody>
169
</table>
170
<h3>Client usage</h3>
171
<table>
172
    <thead>
173
    <tr>
174
        <td>Test</td>
175
        <td>Result</td>
176
    </tr>
177
    </thead>
178
    <tbody>
179
    <?php
180
    $res = phpxmlrpc_verify_compat('client');
181
    foreach ($res as $test => $result) {
182
        echo '<tr><td class="res' . $result['status'] . '">' . htmlspecialchars($test) . '</td><td class="result">' . htmlspecialchars($result['description']) . "</td></tr>\n";
183
    }
184
    ?>
185
    </tbody>
186
</table>
187
</body>
188
</html>
189