Conditions | 12 |
Paths | 27 |
Total Lines | 38 |
Code Lines | 22 |
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 |
||
32 | public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false) |
||
33 | { |
||
34 | $expectedToCompare = $expected; |
||
35 | $actualToCompare = $actual; |
||
36 | |||
37 | // always compare as strings to avoid strange behaviour |
||
38 | // otherwise 0 == 'Foobar' |
||
39 | if (is_string($expected) || is_string($actual)) { |
||
40 | $expectedToCompare = (string) $expectedToCompare; |
||
41 | $actualToCompare = (string) $actualToCompare; |
||
42 | |||
43 | if ($ignoreCase) { |
||
44 | $expectedToCompare = strtolower($expectedToCompare); |
||
45 | $actualToCompare = strtolower($actualToCompare); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | if (is_null($expectedToCompare) && !is_bool($actual) || is_null($actual) && !is_bool($expectedToCompare)) { |
||
50 | if ($expected !== $actual) { |
||
51 | $this->throwComparisonFailureException($expected, $actual); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | if ($expectedToCompare != $actualToCompare) { |
||
56 | if (is_string($expected) && is_string($actual)) { |
||
57 | throw new ComparisonFailure( |
||
58 | $expected, |
||
59 | $actual, |
||
60 | $this->exporter->export($expected), |
||
61 | $this->exporter->export($actual), |
||
62 | false, |
||
63 | 'Failed asserting that two strings are equal.' |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | $this->throwComparisonFailureException($expected, $actual); |
||
68 | } |
||
69 | } |
||
70 | |||
91 |