Completed
Push — master ( 66f3e0...c4596e )
by Gaetano
07:18
created

LocalhostMultiTest   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 226
Duplicated Lines 42.04 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 95
loc 226
rs 9.2
c 0
b 0
f 0
wmc 34
lcom 1
cbo 2

17 Methods

Rating   Name   Duplication   Size   Complexity  
B _runtests() 0 19 5
A testDeflate() 11 11 2
A testGzip() 11 11 2
A testKeepAlives() 11 11 2
A testProxy() 0 10 2
A testHttp11() 14 14 2
A testHttp11Gzip() 14 14 2
A testHttp11Deflate() 14 14 2
A testHttp11Proxy() 10 20 3
A testHttps() 0 16 2
A testHttpsProxy() 10 22 3
A testUTF8Responses() 0 6 1
A testUTF8Requests() 0 5 1
A testISOResponses() 0 6 1
A testISORequests() 0 5 1
A testBasicAuth() 0 6 1
A testDigestAuth() 0 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 14 and the first side effect is on line 3.

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
include_once __DIR__ . '/../lib/xmlrpc.inc';
4
include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
5
6
include_once __DIR__ . '/parse_args.php';
7
8
include_once __DIR__ . '/3LocalhostTest.php';
9
10
/**
11
 * Tests which stress http features of the library.
12
 * Each of these tests iterates over (almost) all of the 'localhost' tests
13
 */
14
class LocalhostMultiTest extends LocalhostTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
15
{
16
    /**
17
     * @todo reintroduce skipping of tests which failed when executed individually if test runs happen as separate processes
18
     * @todo reintroduce skipping of tests within the loop
19
     */
20
    function _runtests()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21
    {
22
        $unsafeMethods = array('testHttps', 'testCatchExceptions', 'testUtf8Method', 'testServerComments', 'testExoticCharsetsRequests',
23
            'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
24
            // @todo the following are currently not compatible w Digest Auth (most likely because of client copy) and should be fixed
25
            'testcatchWarnings', 'testWrappedMethodAsSource', 'testTransferOfObjectViaWrapping');
26
        foreach(get_class_methods('LocalhostTest') as $method)
27
        {
28
            if(strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods))
29
            {
30
                if (!isset(self::$failed_tests[$method]))
31
                    $this->$method();
32
            }
33
            /*if ($this->_failed)
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
            {
35
                break;
36
            }*/
37
        }
38
    }
39
40 View Code Duplication
    function testDeflate()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
41
    {
42
        if(!function_exists('gzdeflate'))
43
        {
44
            $this->markTestSkipped('Zlib missing: cannot test deflate functionality');
45
            return;
46
        }
47
        $this->client->accepted_compression = array('deflate');
48
        $this->client->request_compression = 'deflate';
49
        $this->_runtests();
50
    }
51
52 View Code Duplication
    function testGzip()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
53
    {
54
        if(!function_exists('gzdeflate'))
55
        {
56
            $this->markTestSkipped('Zlib missing: cannot test gzip functionality');
57
            return;
58
        }
59
        $this->client->accepted_compression = array('gzip');
60
        $this->client->request_compression = 'gzip';
61
        $this->_runtests();
62
    }
63
64 View Code Duplication
    function testKeepAlives()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
65
    {
66
        if(!function_exists('curl_init'))
67
        {
68
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
69
            return;
70
        }
71
        $this->method = 'http11';
72
        $this->client->keepalive = true;
73
        $this->_runtests();
74
    }
75
76
    function testProxy()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
77
    {
78
        if ($this->args['PROXYSERVER'])
79
        {
80
            $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
81
            $this->_runtests();
82
        }
83
        else
84
            $this->markTestSkipped('PROXY definition missing: cannot test proxy');
85
    }
86
87 View Code Duplication
    function testHttp11()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
88
    {
89
        if(!function_exists('curl_init'))
90
        {
91
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
92
            return;
93
        }
94
        $this->method = 'http11'; // not an error the double assignment!
95
        $this->client->method = 'http11';
96
        //$this->client->verifyhost = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
        //$this->client->verifypeer = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
        $this->client->keepalive = false;
99
        $this->_runtests();
100
    }
101
102 View Code Duplication
    function testHttp11Gzip()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
103
    {
104
        if(!function_exists('curl_init'))
105
        {
106
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
107
            return;
108
        }
109
        $this->method = 'http11'; // not an error the double assignment!
110
        $this->client->method = 'http11';
111
        $this->client->keepalive = false;
112
        $this->client->accepted_compression = array('gzip');
113
        $this->client->request_compression = 'gzip';
114
        $this->_runtests();
115
    }
116
117 View Code Duplication
    function testHttp11Deflate()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
118
    {
119
        if(!function_exists('curl_init'))
120
        {
121
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
122
            return;
123
        }
124
        $this->method = 'http11'; // not an error the double assignment!
125
        $this->client->method = 'http11';
126
        $this->client->keepalive = false;
127
        $this->client->accepted_compression = array('deflate');
128
        $this->client->request_compression = 'deflate';
129
        $this->_runtests();
130
    }
131
132
    function testHttp11Proxy()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
133
    {
134 View Code Duplication
        if(!function_exists('curl_init'))
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...
135
        {
136
            $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
137
            return;
138
        }
139
        else if ($this->args['PROXYSERVER'] == '')
140
        {
141
            $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
142
            return;
143
        }
144
        $this->method = 'http11'; // not an error the double assignment!
145
        $this->client->method = 'http11';
146
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
147
        //$this->client->verifyhost = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
148
        //$this->client->verifypeer = 0;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
149
        $this->client->keepalive = false;
150
        $this->_runtests();
151
    }
152
153
    function testHttps()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
154
    {
155
        if(!function_exists('curl_init'))
156
        {
157
            $this->markTestSkipped('CURL missing: cannot test https functionality');
158
            return;
159
        }
160
        $this->client->server = $this->args['HTTPSSERVER'];
161
        $this->method = 'https';
162
        $this->client->method = 'https';
163
        $this->client->path = $this->args['HTTPSURI'];
164
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
165
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
166
        $this->client->setSSLVersion($this->args['SSLVERSION']);
167
        $this->_runtests();
168
    }
169
170
    function testHttpsProxy()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
171
    {
172 View Code Duplication
        if(!function_exists('curl_init'))
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...
173
        {
174
            $this->markTestSkipped('CURL missing: cannot test https functionality');
175
            return;
176
        }
177
        else if ($this->args['PROXYSERVER'] == '')
178
        {
179
            $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
180
            return;
181
        }
182
        $this->client->server = $this->args['HTTPSSERVER'];
183
        $this->method = 'https';
184
        $this->client->method = 'https';
185
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
186
        $this->client->path = $this->args['HTTPSURI'];
187
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
188
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
189
        $this->client->setSSLVersion($this->args['SSLVERSION']);
190
        $this->_runtests();
191
    }
192
193
    function testUTF8Responses()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
194
    {
195
        //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
196
        $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=UTF-8';
197
        $this->_runtests();
198
    }
199
200
    function testUTF8Requests()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
201
    {
202
        $this->client->request_charset_encoding = 'UTF-8';
203
        $this->_runtests();
204
    }
205
206
    function testISOResponses()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
207
    {
208
        //$this->client->path = strpos($URI, '?') === null ? $URI.'?RESPONSE_ENCODING=UTF-8' : $URI.'&RESPONSE_ENCODING=UTF-8';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
209
        $this->client->path = $this->args['URI'].'?RESPONSE_ENCODING=ISO-8859-1';
210
        $this->_runtests();
211
    }
212
213
    function testISORequests()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
214
    {
215
        $this->client->request_charset_encoding = 'ISO-8859-1';
216
        $this->_runtests();
217
    }
218
219
    function testBasicAuth()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
220
    {
221
        $this->client->setCredentials('test', 'test');
222
        $this->client->path = $this->args['URI'].'?FORCE_AUTH=Basic';
223
        $this->_runtests();
224
    }
225
226
    function testDigestAuth()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
227
    {
228
        if (!function_exists('curl_init'))
229
        {
230
            $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
231
            return;
232
        }
233
        $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
234
        $this->client->path = $this->args['URI'].'?FORCE_AUTH=Digest';
235
        $this->method = 'http11';
236
        $this->client->method = 'http11';
237
        $this->_runtests();
238
    }
239
}
240