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

PhpXmlRpcProxy::__call()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 2
dl 0
loc 19
ccs 0
cts 15
cp 0
crap 12
rs 9.6333
c 0
b 0
f 0
1
<html>
2
<head><title>xmlrpc - Proxy demo</title></head>
3
<body>
4
<h1>proxy demo</h1>
5
<h2>Query server using a 'proxy' object</h2>
6
<h3>The code demonstrates usage for the terminally lazy. For a more complete proxy, look at at the Wrapper class</h3>
7
<?php
8
9
include_once __DIR__ . "/../../src/Autoloader.php";
10
PhpXmlRpc\Autoloader::register();
11
12
class PhpXmlRpcProxy
13
{
14
    protected $client;
15
    protected $prefix = 'examples.';
16
17
    public function __construct(PhpXmlRpc\Client $client)
18
    {
19
        $this->client = $client;
20
    }
21
22
    /**
23
     * Translates any method call to an xmlrpc call.
24
     *
25
     * @author Toth Istvan
26
     *
27
     * @param string $name remote function name. Will be prefixed
28
     * @param array $arguments
29
     *
30
     * @return mixed
31
     *
32
     * @throws Exception
33
     */
34
    public function __call($name, $arguments)
35
    {
36
        $encoder = new PhpXmlRpc\Encoder();
37
        $valueArray = array();
38
        foreach ($arguments as $parameter) {
39
            $valueArray[] = $encoder->encode($parameter);
40
        }
41
42
        // just in case this was set to something else
43
        $this->client->return_type = 'phpvals';
44
45
        $resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray));
46
47
        if ($resp->faultCode()) {
48
            throw new Exception($resp->faultString(), $resp->faultCode());
49
        } else {
50
            return $resp->value();
51
        }
52
    }
53
54
}
55
56
$stateNo = rand(1, 51);
57
$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client('http://phpxmlrpc.sourceforge.net/server.php'));
58
$stateName = $proxy->getStateName($stateNo);
0 ignored issues
show
Bug introduced by
The method getStateName() does not exist on PhpXmlRpcProxy. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
$stateName = $proxy->/** @scrutinizer ignore-call */ getStateName($stateNo);
Loading history...
59
60
echo "State $stateNo is ".htmlspecialchars($stateName);
61