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.

ObjectCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 57
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 4 4 1
A execute() 49 49 1

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
namespace Clients\RpcEncoded;
3
4
use Clients\InitCommand;
5
use SoapClient;
6
use stdClass;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10 View Code Duplication
class ObjectCommand extends InitCommand
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...
11
{
12
    protected function configure()
13
    {
14
        $this->setName('rpc_encoded:object');
15
    }
16
17
    protected function execute(InputInterface $input, OutputInterface $output)
18
    {
19
        $this->output = $output;
20
21
        $this->soapClient = new SoapClient('http://localhost/wsdl-creator/examples/rpc_encoded/ObjectExampleSoapServer.php?wsdl', array(
22
            'uri' => "http://foo.bar/", 'location' => 'http://localhost/wsdl-creator/examples/rpc_encoded/ObjectExampleSoapServer.php',
23
            'trace' => true, 'cache_wsdl' => WSDL_CACHE_NONE
24
        ));
25
26
        $this->serviceInfo('Client Object - rpc/encoded');
27
28
        $this->renderMethodsTable();
29
30
        $user = new stdClass();
31
        $user->name = 'john';
32
        $user->age = 32;
33
        $response = $this->soapClient->userInfo($user);
34
        $this->method('userInfo', array($user), $response);
35
36
        $response = $this->soapClient->getAgentWithId('peter', 999444);
37
        $this->method('getAgentWithId', array('peter', 999444), $response);
38
39
        $namesInfo = new stdClass();
40
        $namesInfo->names = array('billy', 'clark');
41
        $namesInfo->id = 333;
42
        $response = $this->soapClient->namesForId($namesInfo);
43
        $this->method('namesForId', array($namesInfo), $response);
44
45
        $response = $this->soapClient->getCompanies();
46
        $this->method('getCompanies', array(), $response);
47
48
        $response = $this->soapClient->getListOfAgentsWithId();
49
        $this->method('getListOfAgentsWithId', array(), $response);
50
51
        $payments[0] = new stdClass();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$payments was never initialized. Although not strictly required by PHP, it is generally a good practice to add $payments = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
52
        $payments[0]->payment = array(1.21, 3.21, 100.60);
53
        $payments[0]->user = 'john';
54
        $payments[1] = new stdClass();
55
        $payments[1]->payment = array(120.60);
56
        $payments[1]->user = 'peter';
57
        $response = $this->soapClient->setPayment($payments);
58
        $this->method('setPayment', array($payments), $response);
59
60
        $response = $this->soapClient->getAgentsWithPayment();
61
        $this->method('getAgentsWithPayment', array(), $response);
62
63
        $response = $this->soapClient->getEmployeesWithAgents();
64
        $this->method('getEmployeesWithAgents', array(), $response);
65
    }
66
}