| Conditions | 10 |
| Paths | 64 |
| Total Lines | 42 |
| Code Lines | 27 |
| 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 |
||
| 157 | public function toXML(\DOMElement $parent) |
||
| 158 | { |
||
| 159 | assert(is_string($this->contactType)); |
||
| 160 | assert(is_array($this->Extensions)); |
||
| 161 | assert(is_null($this->Company) || is_string($this->Company)); |
||
| 162 | assert(is_null($this->GivenName) || is_string($this->GivenName)); |
||
| 163 | assert(is_null($this->SurName) || is_string($this->SurName)); |
||
| 164 | assert(is_array($this->EmailAddress)); |
||
| 165 | assert(is_array($this->TelephoneNumber)); |
||
| 166 | assert(is_array($this->ContactPersonAttributes)); |
||
| 167 | |||
| 168 | $doc = $parent->ownerDocument; |
||
| 169 | |||
| 170 | $e = $doc->createElementNS(Constants::NS_MD, 'md:ContactPerson'); |
||
| 171 | $parent->appendChild($e); |
||
| 172 | |||
| 173 | $e->setAttribute('contactType', $this->contactType); |
||
| 174 | |||
| 175 | foreach ($this->ContactPersonAttributes as $attr => $val) { |
||
| 176 | $e->setAttribute($attr, $val); |
||
| 177 | } |
||
| 178 | |||
| 179 | Extensions::addList($e, $this->Extensions); |
||
| 180 | |||
| 181 | if (isset($this->Company)) { |
||
| 182 | Utils::addString($e, Constants::NS_MD, 'md:Company', $this->Company); |
||
| 183 | } |
||
| 184 | if (isset($this->GivenName)) { |
||
| 185 | Utils::addString($e, Constants::NS_MD, 'md:GivenName', $this->GivenName); |
||
| 186 | } |
||
| 187 | if (isset($this->SurName)) { |
||
| 188 | Utils::addString($e, Constants::NS_MD, 'md:SurName', $this->SurName); |
||
| 189 | } |
||
| 190 | if (!empty($this->EmailAddress)) { |
||
| 191 | Utils::addStrings($e, Constants::NS_MD, 'md:EmailAddress', false, $this->EmailAddress); |
||
| 192 | } |
||
| 193 | if (!empty($this->TelephoneNumber)) { |
||
| 194 | Utils::addStrings($e, Constants::NS_MD, 'md:TelephoneNumber', false, $this->TelephoneNumber); |
||
| 195 | } |
||
| 196 | |||
| 197 | return $e; |
||
| 198 | } |
||
| 199 | } |
||
| 200 |