Passed
Push — master ( 67ed62...5da465 )
by Gaetano
02:56
created

PhpXmlRpcProxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 39
ccs 12
cts 13
cp 0.9231
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 17 3
A __construct() 0 3 1
1
<?php require_once __DIR__ . "/_prepend.php"; ?><html lang="en">
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
<p>You can see the source to this page here: <a href="proxy.php?showSource=1">proxy.php</a></p>
8
<?php
9
10
class PhpXmlRpcProxy
11
{
12
    protected $client;
13
    protected $prefix = 'examples.';
14
15 1
    public function __construct(PhpXmlRpc\Client $client)
16
    {
17 1
        $this->client = $client;
18 1
    }
19
20
    /**
21
     * Translates any method call to an xmlrpc call.
22
     *
23
     * @author Toth Istvan
24
     *
25
     * @param string $name remote function name. Will be prefixed
26
     * @param array $arguments
27
     *
28
     * @return mixed
29
     *
30
     * @throws Exception
31
     */
32 1
    public function __call($name, $arguments)
33
    {
34 1
        $encoder = new PhpXmlRpc\Encoder();
35 1
        $valueArray = array();
36 1
        foreach ($arguments as $parameter) {
37 1
            $valueArray[] = $encoder->encode($parameter);
38
        }
39
40
        // just in case this was set to something else
41 1
        $this->client->return_type = 'phpvals';
42
43 1
        $resp = $this->client->send(new PhpXmlRpc\Request($this->prefix.$name, $valueArray));
44
45 1
        if ($resp->faultCode()) {
46
            throw new Exception($resp->faultString(), $resp->faultCode());
47
        } else {
48 1
            return $resp->value();
49
        }
50
    }
51
}
52
53 1
$stateNo = rand(1, 51);
54 1
$proxy = new PhpXmlRpcProxy(new \PhpXmlRpc\Client(XMLRPCSERVER));
55 1
$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

55
$stateName = $proxy->/** @scrutinizer ignore-call */ getStateName($stateNo);
Loading history...
56
57 1
echo "State $stateNo is ".htmlspecialchars($stateName);
58
59
require_once __DIR__ . "/_append.php";
60