Completed
Push — master ( 87b7a4...6ce28d )
by Gaetano
11:11 queued 06:38
created

phpxmlrpc_verify_compat()   C

Complexity

Conditions 17
Paths 48

Size

Total Lines 86
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Importance

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

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-2019 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
 */
11
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
        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
        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
        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
        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
            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...
87
                $tests['curl']['status'] = 1;
88
                $tests['curl']['description'] .= ".\nPlease note that the current cURL install does not support compressed messages";
89
            }
90
            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
100
?>
101
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
102
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
103
<head>
104
    <title>PHP XMLRPC compatibility assessment</title>
105
    <style type="text/css">
106
        body, html {
107
            background-color: white;
108
            font-family: Arial, Verdana, Geneva, sans-serif;
109
            font-size: small;
110
        }
111
112
        table {
113
            border: 1px solid gray;
114
            padding: 0;
115
        }
116
117
        thead {
118
            background-color: silver;
119
            color: black;
120
        }
121
122
        td {
123
            margin: 0;
124
            padding: 0.5em;
125
        }
126
127
        tbody td {
128
            border-top: 1px solid gray;
129
        }
130
131
        .res0 {
132
            background-color: red;
133
            color: black;
134
            border-right: 1px solid gray;
135
        }
136
137
        .res1 {
138
            background-color: yellow;
139
            color: black;
140
            border-right: 1px solid gray;
141
        }
142
143
        .res2 {
144
            background-color: green;
145
            color: black;
146
            border-right: 1px solid gray;
147
        }
148
149
        .result {
150
            white-space: pre;
151
        }
152
    </style>
153
</head>
154
<body>
155
<h1>PHPXMLRPC compatibility assessment with the current PHP install</h1>
156
<h4>For phpxmlrpc version 4.0 or later</h4>
157
158
<h3>Server usage</h3>
159
<table cellspacing="0">
160
    <thead>
161
    <tr>
162
        <td>Test</td>
163
        <td>Result</td>
164
    </tr>
165
    </thead>
166
    <tbody>
167
    <?php
168
    $res = phpxmlrpc_verify_compat('server');
169
    foreach ($res as $test => $result) {
170
        echo '<tr><td class="res' . $result['status'] . '">' . htmlspecialchars($test) . '</td><td class="result">' . htmlspecialchars($result['description']) . "</td></tr>\n";
171
    }
172
    ?>
173
    </tbody>
174
</table>
175
<h3>Client usage</h3>
176
<table cellspacing="0">
177
    <thead>
178
    <tr>
179
        <td>Test</td>
180
        <td>Result</td>
181
    </tr>
182
    </thead>
183
    <tbody>
184
    <?php
185
    $res = phpxmlrpc_verify_compat('client');
186
    foreach ($res as $test => $result) {
187
        echo '<tr><td class="res' . $result['status'] . '">' . htmlspecialchars($test) . '</td><td class="result">' . htmlspecialchars($result['description']) . "</td></tr>\n";
188
    }
189
    ?>
190
    </tbody>
191
</table>
192
</body>
193
</html>
194