| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 52 | 
| Code Lines | 38 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 1 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php  | 
            ||
| 17 | protected function execute(InputInterface $input, OutputInterface $output)  | 
            ||
| 18 |     { | 
            ||
| 19 | $this->output = $output;  | 
            ||
| 20 | |||
| 21 |         $this->soapClient = new SoapClient('http://localhost/wsdl-creator/examples/document_literal_wrapped/ObjectExampleSoapServer.php?wsdl', array( | 
            ||
| 22 | 'uri' => "http://foo.bar/", 'location' => 'http://localhost/wsdl-creator/examples/document_literal_wrapped/ObjectExampleSoapServer.php',  | 
            ||
| 23 | 'trace' => true, 'cache_wsdl' => WSDL_CACHE_NONE  | 
            ||
| 24 | ));  | 
            ||
| 25 | |||
| 26 |         $this->serviceInfo('Client Object - document/literal wrapped'); | 
            ||
| 27 | |||
| 28 | $this->renderMethodsTable();  | 
            ||
| 29 | |||
| 30 | $user = new stdClass();  | 
            ||
| 31 | $user->name = 'john';  | 
            ||
| 32 | $user->age = 32;  | 
            ||
| 33 |         $response = $this->soapClient->userInfo(array('info' => $user)); | 
            ||
| 34 |         $this->method('userInfo', array(array('info' => $user)), $response); | 
            ||
| 35 | |||
| 36 | $params = new stdClass();  | 
            ||
| 37 | $params->name = 'peter';  | 
            ||
| 38 | $params->number = 999444;  | 
            ||
| 39 | $response = $this->soapClient->getAgentWithId($params);  | 
            ||
| 40 |         $this->method('getAgentWithId', array($params), $response); | 
            ||
| 41 | |||
| 42 | $namesInfo = new stdClass();  | 
            ||
| 43 |         $namesInfo->names = array('billy', 'clark'); | 
            ||
| 44 | $namesInfo->id = 333;  | 
            ||
| 45 |         $response = $this->soapClient->namesForId(array('namesInfo' => $namesInfo)); | 
            ||
| 46 |         $this->method('namesForId', array(array('namesInfo' => $namesInfo)), $response); | 
            ||
| 47 | |||
| 48 | $response = $this->soapClient->getCompanies();  | 
            ||
| 49 |         $this->method('getCompanies', array(), $response); | 
            ||
| 50 | |||
| 51 | $response = $this->soapClient->getListOfAgentsWithId();  | 
            ||
| 52 |         $this->method('getListOfAgentsWithId', array(), $response); | 
            ||
| 53 | |||
| 54 | $payments[0] = new stdClass();  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 55 | $payments[0]->payment = array(1.21, 3.21, 100.60);  | 
            ||
| 56 | $payments[0]->user = 'john';  | 
            ||
| 57 | $payments[1] = new stdClass();  | 
            ||
| 58 | $payments[1]->payment = array(120.60);  | 
            ||
| 59 | $payments[1]->user = 'peter';  | 
            ||
| 60 |         $response = $this->soapClient->setPayment(array('payments' => $payments)); | 
            ||
| 61 |         $this->method('setPayment', array(array('payments' => $payments)), $response); | 
            ||
| 62 | |||
| 63 | $response = $this->soapClient->getAgentsWithPayment();  | 
            ||
| 64 |         $this->method('getAgentsWithPayment', array(), $response); | 
            ||
| 65 | |||
| 66 | $response = $this->soapClient->getEmployeesWithAgents();  | 
            ||
| 67 |         $this->method('getEmployeesWithAgents', array(), $response); | 
            ||
| 68 | }  | 
            ||
| 69 | }  | 
            
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:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.