| Conditions | 8 |
| Paths | 26 |
| Total Lines | 52 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 namespace SimpleUPS\AddressValidate; |
||
| 42 | public function buildXml() |
||
| 43 | { |
||
| 44 | if (serialize($this->getAddress()) == serialize(new Address())) { |
||
| 45 | throw new MissingParameterException( |
||
| 46 | 'Address requires a Country code and a City, a State\Province code or a Postal code' |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($this->getAddress()->getCountryCode() === null) { |
||
| 51 | throw new MissingParameterException('Address requires a Country code'); |
||
| 52 | } |
||
| 53 | |||
| 54 | $dom = new \DomDocument('1.0'); |
||
| 55 | $dom->formatOutput = $this->getDebug(); |
||
| 56 | $dom->appendChild($addressRequest = $dom->createElement('AddressValidationRequest')); |
||
| 57 | $addressRequestLang = $dom->createAttribute('xml:lang'); |
||
| 58 | $addressRequestLang->value = parent::getXmlLang(); |
||
|
|
|||
| 59 | $addressRequest->appendChild($request = $dom->createElement('Request')); |
||
| 60 | $request->appendChild($transactionReference = $dom->createElement('TransactionReference')); |
||
| 61 | $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext())); |
||
| 62 | |||
| 63 | $request->appendChild($dom->createElement('RequestAction', 'XAV')); |
||
| 64 | $request->appendChild($dom->createElement('RequestOption', '3')); |
||
| 65 | |||
| 66 | $addressRequest->appendChild($address = $dom->createElement('AddressKeyFormat')); |
||
| 67 | |||
| 68 | $address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getStreet())); |
||
| 69 | if ($this->getAddress()->getAddressLine2()) { |
||
| 70 | $address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getAddressLine2())); |
||
| 71 | if ($this->getAddress()->getAddressLine3()) { |
||
| 72 | $address->appendChild($dom->createElement('AddressLine', $this->getAddress()->getAddressLine3())); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | if ($this->getAddress()->getCity() != null) { |
||
| 76 | $address->appendChild($dom->createElement('PoliticalDivision2', $this->getAddress()->getCity())); |
||
| 77 | } |
||
| 78 | |||
| 79 | if ($this->getAddress()->getStateProvinceCode() != null) { |
||
| 80 | $address->appendChild( |
||
| 81 | $dom->createElement('PoliticalDivision1', $this->getAddress()->getStateProvinceCode()) |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($this->getAddress()->getPostalCode() != null) { |
||
| 86 | $address->appendChild($dom->createElement('PostcodePrimaryLow', $this->getAddress()->getPostalCode())); |
||
| 87 | } |
||
| 88 | |||
| 89 | $address->appendChild($dom->createElement('CountryCode', $this->getAddress()->getCountryCode())); |
||
| 90 | $xml = parent::buildAuthenticationXml() . $dom->saveXML(); |
||
| 91 | |||
| 92 | return $xml; |
||
| 93 | } |
||
| 94 | |||
| 126 | } |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.