Completed
Push — master ( f62d1a...5fc0c8 )
by Gaetano
9s
created

verify_compat.php ➔ phpxmlrpc_verify_compat()   D

Complexity

Conditions 17
Paths 48

Size

Total Lines 87
Code Lines 61

Duplication

Lines 36
Ratio 41.38 %

Importance

Changes 0
Metric Value
cc 17
eloc 61
nc 48
nop 1
dl 36
loc 87
rs 4.8361
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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 101.

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.

Loading history...
2
/**
3
 * Verify compatibility level of current php install with php-xmlrpc lib.
4
 *
5
 * @author Gaetano Giunta
6
 * @copyright (C) 2006-2015 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 View Code Duplication
        if (version_compare($ver, '5.3.0') < 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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']))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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 View Code Duplication
            if (!((is_string($info) && strpos($info, 'OpenSSL') !== null) || isset($info['ssl_version']))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    foreach ($res as $test => $result) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    foreach ($res as $test => $result) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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