| Conditions | 10 |
| Paths | 28 |
| Total Lines | 47 |
| 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 |
||
| 29 | public static function build($buffer, ObjectSpec $objectSpec = null) |
||
| 30 | { |
||
| 31 | $xml = new DOMDocument('1.0', 'UTF-8'); |
||
| 32 | $xml->formatOutput = true; |
||
| 33 | $xml->registerNodeClass('\DOMElement', '\AfriCC\EPP\DOM\DOMElement'); |
||
| 34 | $xml->loadXML($buffer); |
||
| 35 | |||
| 36 | $xpath = new DOMXPath($xml); |
||
| 37 | |||
| 38 | if (is_null($objectSpec)) { |
||
| 39 | $objectSpec = new ObjectSpec(); |
||
| 40 | } |
||
| 41 | |||
| 42 | foreach ($objectSpec->specs as $prefix => $spec) { |
||
| 43 | $xpath->registerNamespace($prefix, $spec['xmlns']); |
||
| 44 | } |
||
| 45 | |||
| 46 | $nodes = $xml->getElementsByTagNameNS($objectSpec->xmlns('epp'), 'epp'); |
||
| 47 | if ($nodes === null || $nodes->length !== 1) { |
||
| 48 | return $buffer; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (!$nodes->item(0)->hasChildNodes()) { |
||
| 52 | return $buffer; |
||
| 53 | } |
||
| 54 | |||
| 55 | foreach ($nodes->item(0)->childNodes as $node) { |
||
| 56 | // ignore non-nodes |
||
| 57 | if ($node->nodeType !== XML_ELEMENT_NODE) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | |||
| 61 | // ok now we can create an object according to the response-frame |
||
| 62 | $frame_type = strtolower($node->localName); |
||
| 63 | if ($frame_type === 'response') { |
||
| 64 | // check if it is a message queue @todo this should go into the response object! |
||
| 65 | $results = $xpath->query('//epp:epp/epp:response/epp:msgQ'); |
||
| 66 | if ($results->length > 0) { |
||
| 67 | return new MessageQueue($xml, $objectSpec); |
||
| 68 | } |
||
| 69 | |||
| 70 | return new Response($xml, $objectSpec); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | return $buffer; |
||
| 75 | } |
||
| 76 | } |
||
| 77 |