| Conditions | 5 |
| Paths | 21 |
| Total Lines | 88 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 117 | public function testCreateFromXML() |
||
| 118 | { |
||
| 119 | $data = array( |
||
| 120 | 'UserID' => '5f1f1b07-a8c4-4d4c-bd5b-cdace6cb7c84', |
||
| 121 | 'FirstName' => 'Bruno', |
||
| 122 | 'LastName' => 'Vandenabeele', |
||
| 123 | 'Street' => 'Oplintersesteenweg', |
||
| 124 | 'Number' => '629', |
||
| 125 | 'CompanyName' => 'Bpost', |
||
| 126 | 'Country' => 'BE', |
||
| 127 | 'DateOfBirth' => '1974-07-02', |
||
| 128 | 'DeliveryCode' => '344337728', |
||
| 129 | 'Email' => '[email protected]', |
||
| 130 | 'MobilePrefix' => '0032', |
||
| 131 | 'MobileNumber' => '475813445', |
||
| 132 | 'Postalcode' => '3300', |
||
| 133 | 'PreferredLanguage' => 'nl-BE', |
||
| 134 | 'ReceivePromotions' => true, |
||
| 135 | 'actived' => true, |
||
| 136 | 'Title' => 'Mr', |
||
| 137 | 'Town' => 'Tienen', |
||
| 138 | 'PackStations' => array( |
||
| 139 | array( |
||
| 140 | 'OrderNumber' => '1', |
||
| 141 | 'PackStationId' => '14472', |
||
| 142 | ), |
||
| 143 | ), |
||
| 144 | ); |
||
| 145 | |||
| 146 | $document = self::createDomDocument(); |
||
| 147 | $customerElement = $document->createElement('Customer'); |
||
| 148 | foreach ($data as $key => $value) { |
||
| 149 | if ($key == 'PackStations') { |
||
| 150 | continue; |
||
| 151 | } |
||
| 152 | |||
| 153 | $customerElement->appendChild( |
||
| 154 | $document->createElement($key, $value) |
||
| 155 | ); |
||
| 156 | } |
||
| 157 | $customerPackStation = $document->createElement('CustomerPackStation'); |
||
| 158 | $customerPackStation->appendChild( |
||
| 159 | $document->createElement('OrderNumber', 1) |
||
| 160 | ); |
||
| 161 | $customerPackStation->appendChild( |
||
| 162 | $document->createElement('PackstationID', 14472) |
||
| 163 | ); |
||
| 164 | $packStations = $document->createElement('PackStations'); |
||
| 165 | $packStations->appendChild($customerPackStation); |
||
| 166 | $customerElement->appendChild($packStations); |
||
| 167 | $document->appendChild($customerElement); |
||
| 168 | |||
| 169 | $customer = Customer::createFromXML( |
||
| 170 | simplexml_load_string( |
||
| 171 | $document->saveXML() |
||
| 172 | ) |
||
| 173 | ); |
||
| 174 | |||
| 175 | $this->assertSame($data['UserID'], $customer->getUserID()); |
||
| 176 | $this->assertSame($data['FirstName'], $customer->getFirstName()); |
||
| 177 | $this->assertSame($data['LastName'], $customer->getLastName()); |
||
| 178 | $this->assertSame($data['Street'], $customer->getStreet()); |
||
| 179 | $this->assertSame($data['Number'], $customer->getNumber()); |
||
| 180 | $this->assertSame($data['CompanyName'], $customer->getCompanyName()); |
||
| 181 | $this->assertEquals(new DateTime($data['DateOfBirth']), $customer->getDateOfBirth()); |
||
| 182 | $this->assertSame($data['DeliveryCode'], $customer->getDeliveryCode()); |
||
| 183 | $this->assertSame($data['Email'], $customer->getEmail()); |
||
| 184 | $this->assertSame($data['MobilePrefix'], $customer->getMobilePrefix()); |
||
| 185 | $this->assertSame($data['MobileNumber'], $customer->getMobileNumber()); |
||
| 186 | $this->assertSame($data['Postalcode'], $customer->getPostalCode()); |
||
| 187 | $this->assertSame($data['PreferredLanguage'], $customer->getPreferredLanguage()); |
||
| 188 | $this->assertSame($data['ReceivePromotions'], $customer->getReceivePromotions()); |
||
| 189 | $this->assertSame($data['actived'], $customer->getActivated()); |
||
| 190 | $this->assertSame($data['Title'] . '.', $customer->getTitle()); |
||
| 191 | $this->assertSame($data['Town'], $customer->getTown()); |
||
| 192 | $packStations = $customer->getPackStations(); |
||
| 193 | $this->assertSame($data['PackStations'][0]['OrderNumber'], $packStations[0]->getOrderNumber()); |
||
| 194 | $this->assertSame($data['PackStations'][0]['PackStationId'], $packStations[0]->getPackStationId()); |
||
| 195 | |||
| 196 | try { |
||
| 197 | $xml = simplexml_load_string('<Customer></Customer>'); |
||
| 198 | Customer::createFromXML($xml); |
||
| 199 | $this->fail('BpostXmlNoUserIdFoundException not launched'); |
||
| 200 | } catch (BpostXmlNoUserIdFoundException $e) { |
||
| 201 | // Nothing, the exception is good |
||
| 202 | $this->assertTrue(true); |
||
| 203 | } catch (Exception $e) { |
||
| 204 | $this->fail('BpostXmlNoUserIdFoundException not caught'); |
||
| 205 | } |
||
| 267 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths