GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WrapperSoapServer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 63
loc 63
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserString() 4 4 1
A getUser() 9 9 1
A getEmployees() 13 13 2
A getEmployeesDepartments() 9 9 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 27 and the first side effect is on line 6.

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
use WSDL\DocumentLiteralWrapper;
3
use WSDL\WSDLCreator;
4
use WSDL\XML\Styles\DocumentLiteralWrapped;
5
6
require_once '../../vendor/autoload.php';
7
8
$wsdl = new WSDLCreator('WrapperSoapServer', 'http://localhost/wsdl-creator/examples/document_literal_wrapped/WrapperExampleSoapServer.php');
9
$wsdl->setNamespace("http://foo.bar/")->setBindingStyle(new DocumentLiteralWrapped());
10
11
if (isset($_GET['wsdl'])) {
12
    $wsdl->renderWSDL();
13
    exit;
14
}
15
16
$wsdl->renderWSDLService();
17
18
$server = new SoapServer('http://localhost/wsdl-creator/examples/document_literal_wrapped/WrapperExampleSoapServer.php?wsdl', array(
19
    'uri' => $wsdl->getNamespaceWithSanitizedClass(),
20
    'location' => $wsdl->getLocation(),
21
    'style' => SOAP_DOCUMENT,
22
    'use' => SOAP_LITERAL
23
));
24
$server->setObject(new DocumentLiteralWrapper(new WrapperSoapServer()));
25
$server->handle();
26
27
class User
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...
28
{
29
    /**
30
     * @type string
31
     */
32
    public $name;
33
    /**
34
     * @type int
35
     */
36
    public $age;
37
    /**
38
     * @type double
39
     */
40
    public $payment;
41
}
42
43
class Employee
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
44
{
45
    /**
46
     * @type int
47
     */
48
    public $id;
49
    /**
50
     * @type string
51
     */
52
    public $department;
53
}
54
55 View Code Duplication
class WrapperSoapServer
0 ignored issues
show
Duplication introduced by
This class 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
56
{
57
    /**
58
     * @WebMethod
59
     * @param wrapper $user @className=User
60
     * @param int $id
61
     * @return string $nameWithAge
62
     */
63
    public function getUserString($user, $id)
64
    {
65
        return '[#' . $id . ']Your name is: ' . $user->name . ' and you have ' . $user->age . ' years old with payment ' . $user->payment;
66
    }
67
68
    /**
69
     * @WebMethod
70
     * @param string $name
71
     * @param string $age
72
     * @param string $payment
73
     * @return wrapper $userReturn @className=User
74
     */
75
    public function getUser($name, $age, $payment)
76
    {
77
        //FIXME incorrect response structure
78
        $user = new User();
79
        $user->name = $name;
80
        $user->age = $age;
0 ignored issues
show
Documentation Bug introduced by
The property $age was declared of type integer, but $age is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
81
        $user->payment = $payment;
0 ignored issues
show
Documentation Bug introduced by
The property $payment was declared of type double, but $payment is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
82
        return $user;
83
    }
84
85
    /**
86
     * @WebMethod
87
     * @return wrapper[] $employees @className=Employee
88
     */
89
    public function getEmployees()
90
    {
91
        //FIXME incorrect response structure
92
        $employees = array();
93
        $departments = array('IT', 'Logistics', 'Management');
94
        for ($i = 0; $i < 3; $i++) {
95
            $employee = new Employee();
96
            $employee->id = 2 + $i + 1;
97
            $employee->department = $departments[$i];
98
            $employees[] = $employee;
99
        }
100
        return $employees;
101
    }
102
103
    /**
104
     * @WebMethod
105
     * @param wrapper[] $employeesList @className=Employee
106
     * @return string $str
107
     */
108
    public function getEmployeesDepartments($employeesList)
109
    {
110
        //FIXME incorrect response structure
111
        $names = array();
112
        foreach ($employeesList as $employee) {
113
            $names[] = $employee->department;
114
        }
115
        return implode(', ', $names);
116
    }
117
}