Conditions | 12 |
Paths | 69 |
Total Lines | 71 |
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 |
||
55 | public function parseFile($filename) |
||
56 | { |
||
57 | if (! is_readable($filename)) { |
||
58 | throw new \UnexpectedValueException(sprintf( |
||
59 | 'File %s is not readable', |
||
60 | basename($filename) |
||
61 | )); |
||
62 | } |
||
63 | $dom = new \DOMDocument(1.0, 'UTF-8'); |
||
64 | $dom->load($filename); |
||
65 | |||
66 | if ($this->getLastLibXmlError()) { |
||
67 | throw new \UnexpectedValueException(sprintf( |
||
68 | 'File %s seems not to be a JUnit-File', |
||
69 | basename($filename) |
||
70 | )); |
||
71 | } |
||
72 | |||
73 | $xpath = new \DOMXPath($dom); |
||
74 | |||
75 | $result = []; |
||
76 | |||
77 | $items = $xpath->query('//testcase'); |
||
78 | foreach ($items as $item) { |
||
79 | $class = $item->getAttribute('class'); |
||
80 | if (! $class) { |
||
81 | $class = explode('::', $item->parentNode->getAttribute('name'))[0]; |
||
82 | } |
||
83 | |||
84 | $type = 'success'; |
||
85 | |||
86 | $element = new \DOMNode(); |
||
87 | |||
88 | foreach ($item->childNodes as $child) { |
||
89 | if ($child->nodeType != XML_ELEMENT_NODE) { |
||
90 | continue; |
||
91 | } |
||
92 | $type = $child->nodeName; |
||
93 | $element = clone($child); |
||
94 | } |
||
95 | |||
96 | $message = $ftype = $addInfo = ''; |
||
97 | |||
98 | switch ($type) { |
||
99 | case 'error': |
||
100 | case 'failure': |
||
101 | if (! $element->hasAttributes()) { |
||
102 | break; |
||
103 | } |
||
104 | $message = $element->attributes->getNamedItem('message'); |
||
105 | if ($message instanceof \DOMAttr) { |
||
106 | $message = $message->value; |
||
107 | } |
||
108 | $ftype = $element->attributes->getNamedItem('type'); |
||
109 | if ($ftype instanceof \DOMAttr) { |
||
110 | $ftype = $ftype->value; |
||
111 | } |
||
112 | $addInfo = $element->textContent; |
||
113 | break; |
||
114 | } |
||
115 | |||
116 | $result[$class . '::' . $item->getAttribute('name')] = [ |
||
117 | 'result' => $type, |
||
118 | 'message' => $message, |
||
119 | 'type' => $ftype, |
||
120 | 'info' => $addInfo, |
||
121 | ]; |
||
122 | } |
||
123 | |||
124 | return $result; |
||
125 | } |
||
126 | } |
||
127 |