Conditions | 15 |
Paths | 20 |
Total Lines | 47 |
Code Lines | 38 |
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 |
||
22 | public static function fromValue($value): XmlContent |
||
23 | { |
||
24 | if (is_string($value)) { |
||
25 | $xmlStr = $value; |
||
26 | $isDoc = self::isXmlDocument($value); |
||
27 | } elseif ($value instanceof XmlContent) { |
||
28 | return $value; |
||
29 | } elseif ($value instanceof \DOMDocument) { |
||
30 | $xmlStr = $value->saveXML(); |
||
31 | if ($xmlStr === false) { |
||
32 | throw new \InvalidArgumentException('value'); |
||
33 | } |
||
34 | $isDoc = true; |
||
35 | } elseif ($value instanceof \DOMNode) { |
||
36 | $d = $value->ownerDocument->saveXML($value); |
||
|
|||
37 | if ($d === false) { |
||
38 | throw new \InvalidArgumentException('value'); |
||
39 | } |
||
40 | $xmlStr = self::getXMLDeclaration($value->ownerDocument) . $d; |
||
41 | $isDoc = true; |
||
42 | } elseif ($value instanceof \DOMNodeList) { |
||
43 | $xmlStr = ($value->length > 0 ? self::getXMLDeclaration($value->item(0)->ownerDocument) : ''); |
||
44 | foreach ($value as $i => $node) { |
||
45 | $n = $node->ownerDocument->saveXML($node); |
||
46 | if ($n === false) { |
||
47 | throw new \InvalidArgumentException("value, node $i"); |
||
48 | } |
||
49 | $xmlStr .= $n; |
||
50 | } |
||
51 | $isDoc = ($value->length == 1); |
||
52 | } elseif ($value instanceof \SimpleXMLElement) { |
||
53 | $xmlStr = $value->saveXML(); |
||
54 | if ($xmlStr === false) { |
||
55 | throw new \InvalidArgumentException('value'); |
||
56 | } |
||
57 | $isDoc = true; |
||
58 | } elseif (is_object($value)) { |
||
59 | $xmlStr = (string)$value; |
||
60 | $isDoc = self::isXmlDocument($xmlStr); |
||
61 | } else { |
||
62 | throw new \InvalidArgumentException('value'); |
||
63 | } |
||
64 | |||
65 | if ($isDoc) { |
||
66 | return new XmlDocument($xmlStr); |
||
67 | } else { |
||
68 | return new XmlContent($xmlStr); |
||
69 | } |
||
119 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.