Completed
Push — master ( 7cb054...584ba8 )
by Tim
44:11 queued 26:38
created

SimpleSoapServer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 39
loc 39
rs 10
wmc 4
lcom 0
cbo 0

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
2
use WSDL\DocumentLiteralWrapper;
3
use WSDL\WSDLCreator;
4
use WSDL\XML\Styles\DocumentLiteralWrapped;
5
6
require_once '../../vendor/autoload.php';
7
8
ini_set("soap.wsdl_cache_enabled", 0);
9
10
$wsdl = new WSDLCreator('SimpleSoapServer', 'http://localhost/wsdl-creator/examples/document_literal_wrapped/SimpleExampleSoapServer.php');
11
$wsdl->setNamespace("http://foo.bar/")->setBindingStyle(new DocumentLiteralWrapped());
12
13
if (isset($_GET['wsdl'])) {
14
    $wsdl->renderWSDL();
15
    exit;
16
}
17
18
$wsdl->renderWSDLService();
19
20
$server = new SoapServer('http://localhost/wsdl-creator/examples/document_literal_wrapped/SimpleExampleSoapServer.php?wsdl', array(
21
    'uri' => $wsdl->getNamespaceWithSanitizedClass(),
22
    'location' => $wsdl->getLocation(),
23
    'style' => SOAP_DOCUMENT,
24
    'use' => SOAP_LITERAL, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS
25
));
26
$server->setObject(new DocumentLiteralWrapper(new SimpleSoapServer()));
27
$server->handle();
28
29
class SimpleSoapServer
30
{
31
    /**
32
     * @WebMethod
33
     * @param string $name
34
     * @param int $age
35
     * @return string $nameWithAge
36
     */
37
    public function getNameWithAge($name, $age)
38
    {
39
        return 'Your name is: ' . $name . ' and you have ' . $age . ' years old';
40
    }
41
42
    /**
43
     * @WebMethod
44
     * @param string[] $names
45
     * @return string $userNames
46
     */
47
    public function getNameForUsers($names)
48
    {
49
        //FIXME correct array of $names
50
        return 'User names: ' . implode(', ', $names);
51
    }
52
53
    /**
54
     * @WebMethod
55
     * @param int $max
56
     * @return string[] $count
57
     */
58
    public function countTo($max)
59
    {
60
        //FIXME incorrect structure of response
61
        $array = array();
62
        for ($i = 0; $i < $max; $i++) {
63
            $array[] = 'Number: ' . ($i + 1);
64
        }
65
        return $array;
66
    }
67
}