| Conditions | 13 |
| Paths | 15 |
| Total Lines | 61 |
| Code Lines | 27 |
| 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 |
||
| 108 | protected function parse_request_data() |
||
| 109 | { |
||
| 110 | if (empty($this->raw_request)) |
||
| 111 | { |
||
| 112 | throw new Exception\Structure('An empty xml request', -50); |
||
| 113 | } |
||
| 114 | |||
| 115 | libxml_use_internal_errors(true); |
||
| 116 | $doc = new \DOMDocument(); |
||
| 117 | if ( ! $doc->loadXML($this->raw_request)) |
||
| 118 | { |
||
| 119 | foreach(libxml_get_errors() as $e){ |
||
| 120 | Log::instance()->error($e->message); |
||
| 121 | } |
||
| 122 | throw new Exception\Structure('The wrong XML is received', -51); |
||
| 123 | } |
||
| 124 | |||
| 125 | // process <Request> group |
||
| 126 | $r = $this->getNodes($doc, 'Request'); |
||
| 127 | |||
| 128 | if (count($r) < 1) |
||
| 129 | { |
||
| 130 | throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
||
| 131 | } |
||
| 132 | |||
| 133 | foreach ($r[0]->childNodes as $child) |
||
| 134 | { |
||
| 135 | if ($child->nodeName == 'DateTime') |
||
| 136 | { |
||
| 137 | $this->parse_request_node($child, 'DateTime'); |
||
| 138 | } |
||
| 139 | elseif ($child->nodeName == 'Sign') |
||
| 140 | { |
||
| 141 | $this->parse_request_node($child, 'Sign'); |
||
| 142 | } |
||
| 143 | elseif (in_array($child->nodeName, $this->operations)) |
||
| 144 | { |
||
| 145 | if ( ! isset($this->Operation)) |
||
| 146 | { |
||
| 147 | $this->Operation = $child->nodeName; |
||
| 148 | } |
||
| 149 | else |
||
| 150 | { |
||
| 151 | throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | if ( ! isset($this->Operation)) |
||
| 157 | { |
||
| 158 | throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
||
| 159 | } |
||
| 160 | |||
| 161 | // process <Operation> group |
||
| 162 | $r = $this->getNodes($doc, $this->Operation); |
||
| 163 | |||
| 164 | foreach ($r[0]->childNodes as $child) |
||
| 165 | { |
||
| 166 | if ($child->nodeName == 'ServiceId') |
||
| 167 | { |
||
| 168 | $this->parse_request_node($child, 'ServiceId'); |
||
| 169 | } |
||
| 310 |