Completed
Push — master ( 8f4643...4ef224 )
by Gaetano
07:48 queued 06:06
created

phpWarningGenerator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Demo server for xmlrpc library.
4
 *
5
 * Implements a lot of webservices, including a suite of services used for
6
 * interoperability testing (validator1 methods), and some whose only purpose
7
 * is to be used for unit-testing the library.
8
 *
9
 * Please do not copy this file verbatim into your production server.
10
 **/
11
12
// give user a chance to see the source for this server instead of running the services
13
if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource'])) {
14
    highlight_file(__FILE__);
15
    die();
16
}
17
18
include_once __DIR__ . "/../../vendor/autoload.php";
19
20
// out-of-band information: let the client manipulate the server operations.
21
// we do this to help the testsuite script: do not reproduce in production!
22
if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
23
    $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = '/tmp/phpxmlrpc_coverage';
24
    if (!is_dir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'])) {
25
        mkdir($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY']);
26
    }
27
28
    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/prepend.php";
29
}
30
31
use PhpXmlRpc\Value;
32
33
/**
34
 * Used to test usage of object methods in dispatch maps and in wrapper code.
35
 */
36
class xmlrpcServerMethodsContainer
37
{
38
    /**
39
     * Method used to test logging of php warnings generated by user functions.
40
     * @param PhpXmlRpc\Request $req
41
     * @return PhpXmlRpc\Response
42
     */
43 18
    public function phpWarningGenerator($req)
0 ignored issues
show
Unused Code introduced by
The parameter $req is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45 18
        $a = $undefinedVariable; // this triggers a warning in E_ALL mode, since $undefinedVariable is undefined
0 ignored issues
show
Bug introduced by
The variable $undefinedVariable does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Unused Code introduced by
$a is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46 18
        return new PhpXmlRpc\Response(new Value(1, Value::$xmlrpcBoolean));
47
    }
48
49
    /**
50
     * Method used to test catching of exceptions in the server.
51
     * @param PhpXmlRpc\Request $req
52
     * @throws Exception
53
     */
54 2
    public function exceptionGenerator($req)
0 ignored issues
show
Unused Code introduced by
The parameter $req is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56 2
        throw new Exception("it's just a test", 1);
57
    }
58
59
    /**
60
     * @param string $msg
61
     */
62 2
    public function debugMessageGenerator($msg)
63
    {
64 2
        PhpXmlRpc\Server::xmlrpc_debugmsg($msg);
65 2
    }
66
67
    /**
68
     * A PHP version of the state-number server. Send me an integer and i'll sell you a state.
69
     * Used to test wrapping of PHP methods into xmlrpc methods.
70
     *
71
     * @param integer $num
72
     * @return string
73
     * @throws Exception
74
     */
75 52
    public static function findState($num)
76
    {
77 52
        return inner_findstate($num);
78
    }
79
80
    /**
81
     * Returns an instance of stdClass.
82
     * Used to test wrapping of PHP objects with class preservation
83
     */
84 1
    public function returnObject()
85
    {
86 1
        $obj = new stdClass();
87 1
        $obj->hello = 'world';
88 1
        return $obj;
89
    }
90
}
91
92
// a PHP version of the state-number server
93
// send me an integer and i'll sell you a state
94
95
$stateNames = array(
96 438
    "Alabama", "Alaska", "Arizona", "Arkansas", "California",
97
    "Colorado", "Columbia", "Connecticut", "Delaware", "Florida",
98
    "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas",
99
    "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan",
100
    "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
101
    "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina",
102
    "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island",
103
    "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
104
    "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming",
105
);
106
107 438
$findstate_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcInt));
108 438
$findstate_doc = 'When passed an integer between 1 and 51 returns the
109
name of a US state, where the integer is the index of that state name
110
in an alphabetic order.';
111
112
function findState($req)
113
{
114 18
    global $stateNames;
115
116 18
    $err = "";
117
    // get the first param
118 18
    $sno = $req->getParam(0);
119
120
    // param must be there and of the correct type: server object does the validation for us
121
122
    // extract the value of the state number
123 18
    $snv = $sno->scalarval();
124
    // look it up in our array (zero-based)
125 18
    if (isset($stateNames[$snv - 1])) {
126 18
        $stateName = $stateNames[$snv - 1];
127
    } else {
128
        // not there, so complain
129
        $err = "I don't have a state for the index '" . $snv . "'";
130
    }
131
132
    // if we generated an error, create an error return response
133 18 View Code Duplication
    if ($err) {
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...
134
        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
135
    } else {
136
        // otherwise, we create the right response with the state name
137 18
        return new PhpXmlRpc\Response(new Value($stateName));
0 ignored issues
show
Bug introduced by
The variable $stateName does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
138
    }
139
}
140
141
/**
142
 * Inner code of the state-number server.
143
 * Used to test wrapping of PHP functions into xmlrpc methods.
144
 *
145
 * @param integer $stateNo the state number
146
 *
147
 * @return string the name of the state (or error description)
148
 *
149
 * @throws Exception if state is not found
150
 */
151
function inner_findstate($stateNo)
152
{
153 120
    global $stateNames;
154
155 120
    if (isset($stateNames[$stateNo - 1])) {
156 120
        return $stateNames[$stateNo - 1];
157
    } else {
158
        // not, there so complain
159 35
        throw new Exception("I don't have a state for the index '" . $stateNo . "'", PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser);
160
    }
161
}
162
163 438
$wrapper = new PhpXmlRpc\Wrapper();
164
165 438
$findstate2_sig = $wrapper->wrapPhpFunction('inner_findstate');
166
167 438
$findstate3_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'));
168
169 438
$obj = new xmlrpcServerMethodsContainer();
170 438
$findstate4_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'));
171
172 438
$findstate5_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
173 438
eval($findstate5_sig['source']);
174
175 438
$findstate6_sig = $wrapper->wrapPhpFunction('inner_findstate', '', array('return_source' => true));
176 438
eval($findstate6_sig['source']);
177
178 438
$findstate7_sig = $wrapper->wrapPhpFunction(array('xmlrpcServerMethodsContainer', 'findState'), '', array('return_source' => true));
179 438
eval($findstate7_sig['source']);
180
181 438
$obj = new xmlrpcServerMethodsContainer();
182 438
$findstate8_sig = $wrapper->wrapPhpFunction(array($obj, 'findstate'), '', array('return_source' => true));
183 438
eval($findstate8_sig['source']);
184
185 438
$findstate9_sig = $wrapper->wrapPhpFunction('xmlrpcServerMethodsContainer::findState', '', array('return_source' => true));
186 438
eval($findstate9_sig['source']);
187
188
$findstate10_sig = array(
189
    "function" => function ($req) { return findState($req); },
190 438
    "signature" => $findstate_sig,
191 438
    "docstring" => $findstate_doc,
192
);
193
194
$findstate11_sig = $wrapper->wrapPhpFunction(function ($stateNo) { return inner_findstate($stateNo); });
195
196 438
$c = new xmlrpcServerMethodsContainer;
197 438
$moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method_type' => 'all'));
198
199 438
$returnObj_sig =  $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true));
200
201
// used to test signatures with NULL params
202
$findstate12_sig = array(
203 438
    array(Value::$xmlrpcString, Value::$xmlrpcInt, Value::$xmlrpcNull),
204 438
    array(Value::$xmlrpcString, Value::$xmlrpcNull, Value::$xmlrpcInt),
205
);
206
207
function findStateWithNulls($req)
208
{
209 18
    $a = $req->getParam(0);
210 18
    $b = $req->getParam(1);
211
212 18
    if ($a->scalartyp() == Value::$xmlrpcNull)
213 18
        return new PhpXmlRpc\Response(new Value(inner_findstate($b->scalarval())));
214
    else
215 18
        return new PhpXmlRpc\Response(new Value(inner_findstate($a->scalarval())));
216
}
217
218 438
$addtwo_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt, Value::$xmlrpcInt));
219 438
$addtwo_doc = 'Add two integers together and return the result';
220 View Code Duplication
function addTwo($req)
0 ignored issues
show
Duplication introduced by
This function 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...
221
{
222 35
    $s = $req->getParam(0);
223 35
    $t = $req->getParam(1);
224
225 35
    return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcInt));
226
}
227
228 438
$addtwodouble_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble, Value::$xmlrpcDouble));
229 438
$addtwodouble_doc = 'Add two doubles together and return the result';
230 View Code Duplication
function addTwoDouble($req)
0 ignored issues
show
Duplication introduced by
This function 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...
231
{
232 18
    $s = $req->getParam(0);
233 18
    $t = $req->getParam(1);
234
235 18
    return new PhpXmlRpc\Response(new Value($s->scalarval() + $t->scalarval(), Value::$xmlrpcDouble));
236
}
237
238 438
$stringecho_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
239 438
$stringecho_doc = 'Accepts a string parameter, returns the string.';
240
function stringEcho($req)
241
{
242
    // just sends back a string
243 60
    return new PhpXmlRpc\Response(new Value($req->getParam(0)->scalarval()));
244
}
245
246 438
$echoback_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
247 438
$echoback_doc = 'Accepts a string parameter, returns the entire incoming payload';
248
function echoBack($req)
249
{
250
    // just sends back a string with what i got sent to me, just escaped, that's all
251
    $s = "I got the following message:\n" . $req->serialize();
252
253
    return new PhpXmlRpc\Response(new Value($s));
254
}
255
256 438
$echosixtyfour_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcBase64));
257 438
$echosixtyfour_doc = 'Accepts a base64 parameter and returns it decoded as a string';
258
function echoSixtyFour($req)
259
{
260
    // Accepts an encoded value, but sends it back as a normal string.
261
    // This is to test that base64 encoding is working as expected
262 18
    $incoming = $req->getParam(0);
263
264 18
    return new PhpXmlRpc\Response(new Value($incoming->scalarval(), Value::$xmlrpcString));
265
}
266
267 438
$bitflipper_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
268 438
$bitflipper_doc = 'Accepts an array of booleans, and returns them inverted';
269
function bitFlipper($req)
270
{
271 18
    $v = $req->getParam(0);
272 18
    $rv = new Value(array(), Value::$xmlrpcArray);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
273
274 18
    foreach ($v as $b) {
275 18
        if ($b->scalarval()) {
276 18
            $rv[] = new Value(false, Value::$xmlrpcBoolean);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
277
        } else {
278 18
            $rv[] = new Value(true, Value::$xmlrpcBoolean);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
279
        }
280
    }
281
282 18
    return new PhpXmlRpc\Response($rv);
283
}
284
285
// Sorting demo
286
//
287
// send me an array of structs thus:
288
//
289
// Dave 35
290
// Edd  45
291
// Fred 23
292
// Barney 37
293
//
294
// and I'll return it to you in sorted order
295
296
function agesorter_compare($a, $b)
297
{
298
    global $agesorter_arr;
299
300
    // don't even ask me _why_ these come padded with hyphens, I couldn't tell you :p
301
    $a = str_replace("-", "", $a);
302
    $b = str_replace("-", "", $b);
303
304
    if ($agesorter_arr[$a] == $agesorter_arr[$b]) {
305
        return 0;
306
    }
307
308
    return ($agesorter_arr[$a] > $agesorter_arr[$b]) ? -1 : 1;
309
}
310
311 438
$agesorter_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
312 438
$agesorter_doc = 'Send this method an array of [string, int] structs, eg:
313
<pre>
314
 Dave   35
315
 Edd    45
316
 Fred   23
317
 Barney 37
318
</pre>
319
And the array will be returned with the entries sorted by their numbers.
320
';
321
function ageSorter($req)
322
{
323
    global $agesorter_arr, $s;
324
325
    PhpXmlRpc\Server::xmlrpc_debugmsg("Entering 'agesorter'");
326
    // get the parameter
327
    $sno = $req->getParam(0);
328
    // error string for [if|when] things go wrong
329
    $err = "";
330
    $agar = array();
331
332
    $max = $sno->count();
333
    PhpXmlRpc\Server::xmlrpc_debugmsg("Found $max array elements");
334
    foreach ($sno as $i => $rec) {
335
        if ($rec->kindOf() != "struct") {
336
            $err = "Found non-struct in array at element $i";
337
            break;
338
        }
339
        // extract name and age from struct
340
        $n = $rec["name"];
341
        $a = $rec["age"];
342
        // $n and $a are xmlrpcvals,
343
        // so get the scalarval from them
344
        $agar[$n->scalarval()] = $a->scalarval();
345
    }
346
347
    // create the output value
348
    $v = new Value(array(), Value::$xmlrpcArray);
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
349
350
    $agesorter_arr = $agar;
351
    // hack, must make global as uksort() won't
352
    // allow us to pass any other auxiliary information
353
    uksort($agesorter_arr, 'agesorter_compare');
354
    foreach($agesorter_arr as $key => $val) {
355
        // recreate each struct element
356
        $v[] = new Value(
357
            array(
0 ignored issues
show
Documentation introduced by
array('name' => new \Php...Rpc\Value($val, 'int')) is of type array<string,object<PhpX...ct<PhpXmlRpc\\Value>"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
358
                "name" => new Value($key),
359
                "age" => new Value($val, "int")
360
            ),
361
            Value::$xmlrpcStruct
362
        );
363
    }
364
365
    if ($err) {
366
        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
367
    } else {
368
        return new PhpXmlRpc\Response($v);
369
    }
370
}
371
372
// signature and instructions, place these in the dispatch map
373
$mailsend_sig = array(array(
374 438
    Value::$xmlrpcBoolean, Value::$xmlrpcString, Value::$xmlrpcString,
375 438
    Value::$xmlrpcString, Value::$xmlrpcString, Value::$xmlrpcString,
376 438
    Value::$xmlrpcString, Value::$xmlrpcString,
377
));
378 438
$mailsend_doc = 'mail.send(recipient, subject, text, sender, cc, bcc, mimetype)<br/>
379
recipient, cc, and bcc are strings, comma-separated lists of email addresses, as described above.<br/>
380
subject is a string, the subject of the message.<br/>
381
sender is a string, it\'s the email address of the person sending the message. This string can not be
382
a comma-separated list, it must contain a single email address only.<br/>
383
text is a string, it contains the body of the message.<br/>
384
mimetype, a string, is a standard MIME type, for example, text/plain.
385
';
386
// WARNING; this functionality depends on the sendmail -t option
387
// it may not work with Windows machines properly; particularly
388
// the Bcc option. Sneak on your friends at your own risk!
389
function mailSend($req)
390
{
391
    $err = "";
392
393
    $mTo = $req->getParam(0);
394
    $mSub = $req->getParam(1);
395
    $mBody = $req->getParam(2);
396
    $mFrom = $req->getParam(3);
397
    $mCc = $req->getParam(4);
398
    $mBcc = $req->getParam(5);
399
    $mMime = $req->getParam(6);
400
401
    if ($mTo->scalarval() == "") {
402
        $err = "Error, no 'To' field specified";
403
    }
404
405
    if ($mFrom->scalarval() == "") {
406
        $err = "Error, no 'From' field specified";
407
    }
408
409
    $msgHdr = "From: " . $mFrom->scalarval() . "\n";
410
    $msgHdr .= "To: " . $mTo->scalarval() . "\n";
411
412
    if ($mCc->scalarval() != "") {
413
        $msgHdr .= "Cc: " . $mCc->scalarval() . "\n";
414
    }
415
    if ($mBcc->scalarval() != "") {
416
        $msgHdr .= "Bcc: " . $mBcc->scalarval() . "\n";
417
    }
418
    if ($mMime->scalarval() != "") {
419
        $msgHdr .= "Content-type: " . $mMime->scalarval() . "\n";
420
    }
421
    $msgHdr .= "X-Mailer: XML-RPC for PHP mailer 1.0";
422
423
    if ($err == "") {
424
        if (!mail("",
425
            $mSub->scalarval(),
426
            $mBody->scalarval(),
427
            $msgHdr)
428
        ) {
429
            $err = "Error, could not send the mail.";
430
        }
431
    }
432
433 View Code Duplication
    if ($err) {
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...
434
        return new PhpXmlRpc\Response(0, PhpXmlRpc\PhpXmlRpc::$xmlrpcerruser, $err);
435
    } else {
436
        return new PhpXmlRpc\Response(new Value(true, Value::$xmlrpcBoolean));
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
437
    }
438
}
439
440 438
$getallheaders_sig = array(array(Value::$xmlrpcStruct));
441 438
$getallheaders_doc = 'Returns a struct containing all the HTTP headers received with the request. Provides limited functionality with IIS';
442
function getAllHeaders_xmlrpc($req)
0 ignored issues
show
Unused Code introduced by
The parameter $req is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
443
{
444
    $encoder = new PhpXmlRpc\Encoder();
445
446
    if (function_exists('getallheaders')) {
447
        return new PhpXmlRpc\Response($encoder->encode(getallheaders()));
448
    } else {
449
        $headers = array();
450
        // IIS: poor man's version of getallheaders
451
        foreach ($_SERVER as $key => $val) {
452
            if (strpos($key, 'HTTP_') === 0) {
453
                $key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5))));
454
                $headers[$key] = $val;
455
            }
456
        }
457
458
        return new PhpXmlRpc\Response($encoder->encode($headers));
459
    }
460
}
461
462 438
$setcookies_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
463 438
$setcookies_doc = 'Sends to client a response containing a single \'1\' digit, and sets to it http cookies as received in the request (array of structs describing a cookie)';
464
function setCookies($req)
465
{
466 18
    $encoder = new PhpXmlRpc\Encoder();
467 18
    $cookies = $req->getParam(0);
468 18
    foreach ($cookies as $name => $value) {
469 18
        $cookieDesc = $encoder->decode($value);
470 18
        setcookie($name, @$cookieDesc['value'], @$cookieDesc['expires'], @$cookieDesc['path'], @$cookieDesc['domain'], @$cookieDesc['secure']);
471
    }
472
473 18
    return new PhpXmlRpc\Response(new Value(1, Value::$xmlrpcInt));
474
}
475
476 438
$getcookies_sig = array(array(Value::$xmlrpcStruct));
477 438
$getcookies_doc = 'Sends to client a response containing all http cookies as received in the request (as struct)';
478
function getCookies($req)
0 ignored issues
show
Unused Code introduced by
The parameter $req is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
479
{
480 1
    $encoder = new PhpXmlRpc\Encoder();
481 1
    return new PhpXmlRpc\Response($encoder->encode($_COOKIE));
482
}
483
484 438
$v1_arrayOfStructs_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcArray));
485 438
$v1_arrayOfStructs_doc = 'This handler takes a single parameter, an array of structs, each of which contains at least three elements named moe, larry and curly, all <i4>s. Your handler must add all the struct elements named curly and return the result.';
486
function v1_arrayOfStructs($req)
487
{
488
    $sno = $req->getParam(0);
489
    $numCurly = 0;
490
    foreach ($sno as $str) {
491
        foreach ($str as $key => $val) {
492
            if ($key == "curly") {
493
                $numCurly += $val->scalarval();
494
            }
495
        }
496
    }
497
498
    return new PhpXmlRpc\Response(new Value($numCurly, Value::$xmlrpcInt));
499
}
500
501 438
$v1_easyStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
502 438
$v1_easyStruct_doc = 'This handler takes a single parameter, a struct, containing at least three elements named moe, larry and curly, all &lt;i4&gt;s. Your handler must add the three numbers and return the result.';
503
function v1_easyStruct($req)
504
{
505
    $sno = $req->getParam(0);
506
    $moe = $sno["moe"];
507
    $larry = $sno["larry"];
508
    $curly = $sno["curly"];
509
    $num = $moe->scalarval() + $larry->scalarval() + $curly->scalarval();
510
511
    return new PhpXmlRpc\Response(new Value($num, Value::$xmlrpcInt));
512
}
513
514 438
$v1_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct));
515 438
$v1_echoStruct_doc = 'This handler takes a single parameter, a struct. Your handler must return the struct.';
516
function v1_echoStruct($req)
517
{
518 18
    $sno = $req->getParam(0);
519
520 18
    return new PhpXmlRpc\Response($sno);
521
}
522
523
$v1_manyTypes_sig = array(array(
524 438
    Value::$xmlrpcArray, Value::$xmlrpcInt, Value::$xmlrpcBoolean,
525 438
    Value::$xmlrpcString, Value::$xmlrpcDouble, Value::$xmlrpcDateTime,
526 438
    Value::$xmlrpcBase64,
527
));
528 438
$v1_manyTypes_doc = 'This handler takes six parameters, and returns an array containing all the parameters.';
529
function v1_manyTypes($req)
530
{
531
    return new PhpXmlRpc\Response(new Value(
532
        array(
0 ignored issues
show
Documentation introduced by
array($req->getParam(0),...(4), $req->getParam(5)) is of type array<integer,?,{"0":"?"...":"?","4":"?","5":"?"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
533
            $req->getParam(0),
534
            $req->getParam(1),
535
            $req->getParam(2),
536
            $req->getParam(3),
537
            $req->getParam(4),
538
            $req->getParam(5)
539
        ),
540
        Value::$xmlrpcArray
541
    ));
542
}
543
544 438
$v1_moderateSizeArrayCheck_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcArray));
545 438
$v1_moderateSizeArrayCheck_doc = 'This handler takes a single parameter, which is an array containing between 100 and 200 elements. Each of the items is a string, your handler must return a string containing the concatenated text of the first and last elements.';
546
function v1_moderateSizeArrayCheck($req)
547
{
548
    $ar = $req->getParam(0);
549
    $sz = $ar->count();
550
    $first = $ar[0];
551
    $last = $ar[$sz - 1];
552
553
    return new PhpXmlRpc\Response(new Value($first->scalarval() .
554
        $last->scalarval(), Value::$xmlrpcString));
555
}
556
557 438
$v1_simpleStructReturn_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcInt));
558 438
$v1_simpleStructReturn_doc = 'This handler takes one parameter, and returns a struct containing three elements, times10, times100 and times1000, the result of multiplying the number by 10, 100 and 1000.';
559
function v1_simpleStructReturn($req)
560
{
561
    $sno = $req->getParam(0);
562
    $v = $sno->scalarval();
563
564
    return new PhpXmlRpc\Response(new Value(
565
        array(
0 ignored issues
show
Documentation introduced by
array('times10' => new \...Rpc\Value::$xmlrpcInt)) is of type array<string,object<PhpX...ct<PhpXmlRpc\\Value>"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
566
            "times10" => new Value($v * 10, Value::$xmlrpcInt),
567
            "times100" => new Value($v * 100, Value::$xmlrpcInt),
568
            "times1000" => new Value($v * 1000, Value::$xmlrpcInt)
569
        ),
570
        Value::$xmlrpcStruct
571
    ));
572
}
573
574 438
$v1_nestedStruct_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcStruct));
575 438
$v1_nestedStruct_doc = 'This handler takes a single parameter, a struct, that models a daily calendar. At the top level, there is one struct for each year. Each year is broken down into months, and months into days. Most of the days are empty in the struct you receive, but the entry for April 1, 2000 contains a least three elements named moe, larry and curly, all &lt;i4&gt;s. Your handler must add the three numbers and return the result.';
576
function v1_nestedStruct($req)
577
{
578
    $sno = $req->getParam(0);
579
580
    $twoK = $sno["2000"];
581
    $april = $twoK["04"];
582
    $fools = $april["01"];
583
    $curly = $fools["curly"];
584
    $larry = $fools["larry"];
585
    $moe = $fools["moe"];
586
587
    return new PhpXmlRpc\Response(new Value($curly->scalarval() + $larry->scalarval() + $moe->scalarval(), Value::$xmlrpcInt));
588
}
589
590 438
$v1_countTheEntities_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcString));
591 438
$v1_countTheEntities_doc = 'This handler takes a single parameter, a string, that contains any number of predefined entities, namely &lt;, &gt;, &amp; \' and ".<BR>Your handler must return a struct that contains five fields, all numbers: ctLeftAngleBrackets, ctRightAngleBrackets, ctAmpersands, ctApostrophes, ctQuotes.';
592
function v1_countTheEntities($req)
593
{
594 18
    $sno = $req->getParam(0);
595 18
    $str = $sno->scalarval();
596 18
    $gt = 0;
597 18
    $lt = 0;
598 18
    $ap = 0;
599 18
    $qu = 0;
600 18
    $amp = 0;
601 18
    for ($i = 0; $i < strlen($str); $i++) {
602 18
        $c = substr($str, $i, 1);
603 18
        switch ($c) {
604 18
            case ">":
605 18
                $gt++;
606 18
                break;
607 18
            case "<":
608 18
                $lt++;
609 18
                break;
610 18
            case "\"":
611
                $qu++;
612
                break;
613 18
            case "'":
614 18
                $ap++;
615 18
                break;
616 18
            case "&":
617 18
                $amp++;
618 18
                break;
619
            default:
620 18
                break;
621
        }
622
    }
623
624 18
    return new PhpXmlRpc\Response(new Value(
625
        array(
0 ignored issues
show
Documentation introduced by
array('ctLeftAngleBracke...Rpc\Value::$xmlrpcInt)) is of type array<string,object<PhpX...ct<PhpXmlRpc\\Value>"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
626 18
            "ctLeftAngleBrackets" => new Value($lt, Value::$xmlrpcInt),
627 18
            "ctRightAngleBrackets" => new Value($gt, Value::$xmlrpcInt),
628 18
            "ctAmpersands" => new Value($amp, Value::$xmlrpcInt),
629 18
            "ctApostrophes" => new Value($ap, Value::$xmlrpcInt),
630 18
            "ctQuotes" => new Value($qu, Value::$xmlrpcInt)
631
        ),
632 18
        Value::$xmlrpcStruct
633
    ));
634
}
635
636
// trivial interop tests
637
// http://www.xmlrpc.com/stories/storyReader$1636
638
639 438
$i_echoString_sig = array(array(Value::$xmlrpcString, Value::$xmlrpcString));
640 438
$i_echoString_doc = "Echoes string.";
641
642 438
$i_echoStringArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
643 438
$i_echoStringArray_doc = "Echoes string array.";
644
645 438
$i_echoInteger_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt));
646 438
$i_echoInteger_doc = "Echoes integer.";
647
648 438
$i_echoIntegerArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
649 438
$i_echoIntegerArray_doc = "Echoes integer array.";
650
651 438
$i_echoFloat_sig = array(array(Value::$xmlrpcDouble, Value::$xmlrpcDouble));
652 438
$i_echoFloat_doc = "Echoes float.";
653
654 438
$i_echoFloatArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
655 438
$i_echoFloatArray_doc = "Echoes float array.";
656
657 438
$i_echoStruct_sig = array(array(Value::$xmlrpcStruct, Value::$xmlrpcStruct));
658 438
$i_echoStruct_doc = "Echoes struct.";
659
660 438
$i_echoStructArray_sig = array(array(Value::$xmlrpcArray, Value::$xmlrpcArray));
661 438
$i_echoStructArray_doc = "Echoes struct array.";
662
663 438
$i_echoValue_doc = "Echoes any value back.";
664 438
$i_echoValue_sig = array(array(Value::$xmlrpcValue, Value::$xmlrpcValue));
665
666 438
$i_echoBase64_sig = array(array(Value::$xmlrpcBase64, Value::$xmlrpcBase64));
667 438
$i_echoBase64_doc = "Echoes base64.";
668
669 438
$i_echoDate_sig = array(array(Value::$xmlrpcDateTime, Value::$xmlrpcDateTime));
670 438
$i_echoDate_doc = "Echoes dateTime.";
671
672
function i_echoParam($req)
673
{
674
    $s = $req->getParam(0);
675
676
    return new PhpXmlRpc\Response($s);
677
}
678
679
function i_echoString($req)
680
{
681
    return i_echoParam($req);
682
}
683
684
function i_echoInteger($req)
685
{
686
    return i_echoParam($req);
687
}
688
689
function i_echoFloat($req)
690
{
691
    return i_echoParam($req);
692
}
693
694
function i_echoStruct($req)
695
{
696
    return i_echoParam($req);
697
}
698
699
function i_echoStringArray($req)
700
{
701
    return i_echoParam($req);
702
}
703
704
function i_echoIntegerArray($req)
705
{
706
    return i_echoParam($req);
707
}
708
709
function i_echoFloatArray($req)
710
{
711
    return i_echoParam($req);
712
}
713
714
function i_echoStructArray($req)
715
{
716
    return i_echoParam($req);
717
}
718
719
function i_echoValue($req)
720
{
721
    return i_echoParam($req);
722
}
723
724
function i_echoBase64($req)
725
{
726
    return i_echoParam($req);
727
}
728
729
function i_echoDate($req)
730
{
731
    return i_echoParam($req);
732
}
733
734 438
$i_whichToolkit_sig = array(array(Value::$xmlrpcStruct));
735 438
$i_whichToolkit_doc = "Returns a struct containing the following strings: toolkitDocsUrl, toolkitName, toolkitVersion, toolkitOperatingSystem.";
736
737
function i_whichToolkit($req)
0 ignored issues
show
Unused Code introduced by
The parameter $req is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
738
{
739
    global $SERVER_SOFTWARE;
740
    $ret = array(
741
        "toolkitDocsUrl" => "http://phpxmlrpc.sourceforge.net/",
742
        "toolkitName" => PhpXmlRpc\PhpXmlRpc::$xmlrpcName,
743
        "toolkitVersion" => PhpXmlRpc\PhpXmlRpc::$xmlrpcVersion,
744
        "toolkitOperatingSystem" => isset($SERVER_SOFTWARE) ? $SERVER_SOFTWARE : $_SERVER['SERVER_SOFTWARE'],
745
    );
746
747
    $encoder = new PhpXmlRpc\Encoder();
748
    return new PhpXmlRpc\Response($encoder->encode($ret));
749
}
750
751 438
$object = new xmlrpcServerMethodsContainer();
752
$signatures = array(
753
    "examples.getStateName" => array(
754 438
        "function" => "findState",
755 438
        "signature" => $findstate_sig,
756 438
        "docstring" => $findstate_doc,
757
    ),
758
    "examples.sortByAge" => array(
759 438
        "function" => "ageSorter",
760 438
        "signature" => $agesorter_sig,
761 438
        "docstring" => $agesorter_doc,
762
    ),
763
    "examples.addtwo" => array(
764 438
        "function" => "addTwo",
765 438
        "signature" => $addtwo_sig,
766 438
        "docstring" => $addtwo_doc,
767
    ),
768
    "examples.addtwodouble" => array(
769 438
        "function" => "addTwoDouble",
770 438
        "signature" => $addtwodouble_sig,
771 438
        "docstring" => $addtwodouble_doc,
772
    ),
773
    "examples.stringecho" => array(
774 438
        "function" => "stringEcho",
775 438
        "signature" => $stringecho_sig,
776 438
        "docstring" => $stringecho_doc,
777
    ),
778
    "examples.echo" => array(
779 438
        "function" => "echoBack",
780 438
        "signature" => $echoback_sig,
781 438
        "docstring" => $echoback_doc,
782
    ),
783
    "examples.decode64" => array(
784 438
        "function" => "echoSixtyFour",
785 438
        "signature" => $echosixtyfour_sig,
786 438
        "docstring" => $echosixtyfour_doc,
787
    ),
788
    "examples.invertBooleans" => array(
789 438
        "function" => "bitFlipper",
790 438
        "signature" => $bitflipper_sig,
791 438
        "docstring" => $bitflipper_doc,
792
    ),
793
    // signature omitted on purpose
794
    "tests.generatePHPWarning" => array(
795 438
        "function" => array($object, "phpWarningGenerator"),
796
    ),
797
    // signature omitted on purpose
798
    "tests.raiseException" => array(
799 438
        "function" => array($object, "exceptionGenerator"),
800
    ),
801
    // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
802
    // NB: we can only register this when setting internal encoding to UTF-8, or it will break system.listMethods
803
    "tests.utf8methodname." . 'κόσμε' => array(
804 438
        "function" => "stringEcho",
805 438
        "signature" => $stringecho_sig,
806 438
        "docstring" => $stringecho_doc,
807
    ),
808
    /*"tests.iso88591methodname." . chr(224) . chr(252) . chr(232) => array(
809
        "function" => "stringEcho",
810
        "signature" => $stringecho_sig,
811
        "docstring" => $stringecho_doc,
812
    ),*/
813
    "examples.getallheaders" => array(
814 438
        "function" => 'getAllHeaders_xmlrpc',
815 438
        "signature" => $getallheaders_sig,
816 438
        "docstring" => $getallheaders_doc,
817
    ),
818
    "examples.setcookies" => array(
819 438
        "function" => 'setCookies',
820 438
        "signature" => $setcookies_sig,
821 438
        "docstring" => $setcookies_doc,
822
    ),
823
    "examples.getcookies" => array(
824 438
        "function" => 'getCookies',
825 438
        "signature" => $getcookies_sig,
826 438
        "docstring" => $getcookies_doc,
827
    ),
828
    "mail.send" => array(
829 438
        "function" => "mailSend",
830 438
        "signature" => $mailsend_sig,
831 438
        "docstring" => $mailsend_doc,
832
    ),
833
    "validator1.arrayOfStructsTest" => array(
834 438
        "function" => "v1_arrayOfStructs",
835 438
        "signature" => $v1_arrayOfStructs_sig,
836 438
        "docstring" => $v1_arrayOfStructs_doc,
837
    ),
838
    "validator1.easyStructTest" => array(
839 438
        "function" => "v1_easyStruct",
840 438
        "signature" => $v1_easyStruct_sig,
841 438
        "docstring" => $v1_easyStruct_doc,
842
    ),
843
    "validator1.echoStructTest" => array(
844 438
        "function" => "v1_echoStruct",
845 438
        "signature" => $v1_echoStruct_sig,
846 438
        "docstring" => $v1_echoStruct_doc,
847
    ),
848
    "validator1.manyTypesTest" => array(
849 438
        "function" => "v1_manyTypes",
850 438
        "signature" => $v1_manyTypes_sig,
851 438
        "docstring" => $v1_manyTypes_doc,
852
    ),
853
    "validator1.moderateSizeArrayCheck" => array(
854 438
        "function" => "v1_moderateSizeArrayCheck",
855 438
        "signature" => $v1_moderateSizeArrayCheck_sig,
856 438
        "docstring" => $v1_moderateSizeArrayCheck_doc,
857
    ),
858
    "validator1.simpleStructReturnTest" => array(
859 438
        "function" => "v1_simpleStructReturn",
860 438
        "signature" => $v1_simpleStructReturn_sig,
861 438
        "docstring" => $v1_simpleStructReturn_doc,
862
    ),
863
    "validator1.nestedStructTest" => array(
864 438
        "function" => "v1_nestedStruct",
865 438
        "signature" => $v1_nestedStruct_sig,
866 438
        "docstring" => $v1_nestedStruct_doc,
867
    ),
868
    "validator1.countTheEntities" => array(
869 438
        "function" => "v1_countTheEntities",
870 438
        "signature" => $v1_countTheEntities_sig,
871 438
        "docstring" => $v1_countTheEntities_doc,
872
    ),
873
    "interopEchoTests.echoString" => array(
874 438
        "function" => "i_echoString",
875 438
        "signature" => $i_echoString_sig,
876 438
        "docstring" => $i_echoString_doc,
877
    ),
878
    "interopEchoTests.echoStringArray" => array(
879 438
        "function" => "i_echoStringArray",
880 438
        "signature" => $i_echoStringArray_sig,
881 438
        "docstring" => $i_echoStringArray_doc,
882
    ),
883
    "interopEchoTests.echoInteger" => array(
884 438
        "function" => "i_echoInteger",
885 438
        "signature" => $i_echoInteger_sig,
886 438
        "docstring" => $i_echoInteger_doc,
887
    ),
888
    "interopEchoTests.echoIntegerArray" => array(
889 438
        "function" => "i_echoIntegerArray",
890 438
        "signature" => $i_echoIntegerArray_sig,
891 438
        "docstring" => $i_echoIntegerArray_doc,
892
    ),
893
    "interopEchoTests.echoFloat" => array(
894 438
        "function" => "i_echoFloat",
895 438
        "signature" => $i_echoFloat_sig,
896 438
        "docstring" => $i_echoFloat_doc,
897
    ),
898
    "interopEchoTests.echoFloatArray" => array(
899 438
        "function" => "i_echoFloatArray",
900 438
        "signature" => $i_echoFloatArray_sig,
901 438
        "docstring" => $i_echoFloatArray_doc,
902
    ),
903
    "interopEchoTests.echoStruct" => array(
904 438
        "function" => "i_echoStruct",
905 438
        "signature" => $i_echoStruct_sig,
906 438
        "docstring" => $i_echoStruct_doc,
907
    ),
908
    "interopEchoTests.echoStructArray" => array(
909 438
        "function" => "i_echoStructArray",
910 438
        "signature" => $i_echoStructArray_sig,
911 438
        "docstring" => $i_echoStructArray_doc,
912
    ),
913
    "interopEchoTests.echoValue" => array(
914 438
        "function" => "i_echoValue",
915 438
        "signature" => $i_echoValue_sig,
916 438
        "docstring" => $i_echoValue_doc,
917
    ),
918
    "interopEchoTests.echoBase64" => array(
919 438
        "function" => "i_echoBase64",
920 438
        "signature" => $i_echoBase64_sig,
921 438
        "docstring" => $i_echoBase64_doc,
922
    ),
923
    "interopEchoTests.echoDate" => array(
924 438
        "function" => "i_echoDate",
925 438
        "signature" => $i_echoDate_sig,
926 438
        "docstring" => $i_echoDate_doc,
927
    ),
928
    "interopEchoTests.whichToolkit" => array(
929 438
        "function" => "i_whichToolkit",
930 438
        "signature" => $i_whichToolkit_sig,
931 438
        "docstring" => $i_whichToolkit_doc,
932
    ),
933
934 438
    'tests.getStateName.2' => $findstate2_sig,
935 438
    'tests.getStateName.3' => $findstate3_sig,
936 438
    'tests.getStateName.4' => $findstate4_sig,
937 438
    'tests.getStateName.5' => $findstate5_sig,
938 438
    'tests.getStateName.6' => $findstate6_sig,
939 438
    'tests.getStateName.7' => $findstate7_sig,
940 438
    'tests.getStateName.8' => $findstate8_sig,
941 438
    'tests.getStateName.9' => $findstate9_sig,
942 438
    'tests.getStateName.10' => $findstate10_sig,
943 438
    'tests.getStateName.11' => $findstate11_sig,
944
945
    'tests.getStateName.12' => array(
946 438
        "function" => "findStateWithNulls",
947 438
        "signature" => $findstate12_sig,
948 438
        "docstring" => $findstate_doc,
949
    ),
950
951 438
    'tests.returnPhpObject' => $returnObj_sig,
952
);
953
954 438
$signatures = array_merge($signatures, $moreSignatures);
955
956
// Enable support for the NULL extension
957 438
PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_extension = true;
958
959 438
$s = new PhpXmlRpc\Server($signatures, false);
960 438
$s->setdebug(3);
961 438
$s->compress_response = true;
962
963
// Out-of-band information: let the client manipulate the server operations.
964
// We do this to help the testsuite script: do not reproduce in production!
965 438
if (isset($_GET['RESPONSE_ENCODING'])) {
966 50
    $s->response_charset_encoding = $_GET['RESPONSE_ENCODING'];
967
}
968 438
if (isset($_GET['DETECT_ENCODINGS'])) {
969 4
    PhpXmlRpc\PhpXmlRpc::$xmlrpc_detectencodings = $_GET['DETECT_ENCODINGS'];
970
}
971 438
if (isset($_GET['EXCEPTION_HANDLING'])) {
972 2
    $s->exception_handling = $_GET['EXCEPTION_HANDLING'];
973
}
974 438
if (isset($_GET['FORCE_AUTH'])) {
975
    // We implement both  Basic and Digest auth in php to avoid having to set it up in a vhost.
976
    // Code taken from php.net
977
    // NB: we do NOT check for valid credentials!
978 50
    if ($_GET['FORCE_AUTH'] == 'Basic') {
979 25
        if (!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['REMOTE_USER']) && !isset($_SERVER['REDIRECT_REMOTE_USER'])) {
980
            header('HTTP/1.0 401 Unauthorized');
981
            header('WWW-Authenticate: Basic realm="Phpxmlrpc Basic Realm"');
982
            die('Text visible if user hits Cancel button');
983
        }
984 25
    } elseif ($_GET['FORCE_AUTH'] == 'Digest') {
985 25
        if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
986
            header('HTTP/1.1 401 Unauthorized');
987
            header('WWW-Authenticate: Digest realm="Phpxmlrpc Digest Realm",qop="auth",nonce="'.uniqid().'",opaque="'.md5('Phpxmlrpc Digest Realm').'"');
988
            die('Text visible if user hits Cancel button');
989
        }
990
    }
991
}
992
993 438
$s->service();
994
// That should do all we need!
995
996
// Out-of-band information: let the client manipulate the server operations.
997
// We do this to help the testsuite script: do not reproduce in production!
998 438
if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
999 438
    include_once __DIR__ . "/../../vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/SeleniumCommon/append.php";
1000
}
1001