Conditions | 6 |
Paths | 8 |
Total Lines | 66 |
Code Lines | 43 |
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 |
||
50 | public static function assertSameNormalized($string1, $string2, $message, $xhtml = true) { |
||
51 | |||
52 | $t_result = $string1; |
||
53 | $t_output = $string2; |
||
54 | |||
55 | // DOMDocuments |
||
56 | if ($xhtml) { |
||
57 | $document = new DOMDocument(); |
||
58 | $doc_result = $document->loadXML('<!DOCTYPE html>' . |
||
59 | "<html xmlns='http://www.w3.org/1999/xhtml'>" . |
||
60 | "<body>$t_result</body></html>"); |
||
61 | |||
62 | $document2 = new DOMDocument(); |
||
63 | $doc_output = $document2->loadXML('<!DOCTYPE html>' . |
||
64 | "<html xmlns='http://www.w3.org/1999/xhtml'>" . |
||
65 | "<body>$t_output</body></html>"); |
||
66 | |||
67 | if ($doc_result) { |
||
68 | static::normalizeElementContent($document->documentElement, false); |
||
69 | $n_result = $document->saveXML(); |
||
70 | } else { |
||
71 | $n_result = '--- Expected Result: XML Parse Error ---'; |
||
72 | } |
||
73 | if ($doc_output) { |
||
74 | static::normalizeElementContent($document2->documentElement, false); |
||
75 | $n_output = $document2->saveXML(); |
||
76 | } else { |
||
77 | $n_output = '--- Output: XML Parse Error ---'; |
||
78 | } |
||
79 | } else { |
||
80 | |||
81 | // '@' suppressors used because some tests have invalid HTML (multiple elements with the same id attribute) |
||
82 | // Perhaps isolate to a separate test and remove this? |
||
83 | |||
84 | $document = new DOMDocument(); |
||
85 | $doc_result = @$document->loadHTML($t_result); |
||
86 | |||
87 | $document2 = new DOMDocument(); |
||
88 | $doc_output = @$document2->loadHTML($t_output); |
||
89 | |||
90 | if ($doc_result) { |
||
91 | static::normalizeElementContent($document->documentElement, false); |
||
92 | $n_result = $document->saveHTML(); |
||
93 | } else { |
||
94 | $n_result = '--- Expected Result: HTML Parse Error ---'; |
||
95 | } |
||
96 | |||
97 | if ($doc_output) { |
||
98 | static::normalizeElementContent($document2->documentElement, false); |
||
99 | $n_output = $document2->saveHTML(); |
||
100 | } else { |
||
101 | $n_output = '--- Output: HTML Parse Error ---'; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | $n_result = preg_replace('{^.*?<body>|</body>.*?$}is', '', $n_result); |
||
106 | $n_output = preg_replace('{^.*?<body>|</body>.*?$}is', '', $n_output); |
||
107 | |||
108 | $c_result = $n_result; |
||
109 | $c_output = $n_output; |
||
110 | |||
111 | $c_result = trim($c_result) . "\n"; |
||
112 | $c_output = trim($c_output) . "\n"; |
||
113 | |||
114 | // This will throw a test exception if the strings don't exactly match |
||
115 | TestCase::assertSame($c_result, $c_output, $message); |
||
116 | } |
||
268 |