Conditions | 1 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 45 |
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 |
||
13 | public function testFindLowerOrHigher() |
||
14 | { |
||
15 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
16 | 1337, |
||
17 | [1000, 2000, 3000], |
||
18 | SortedNumericArrayNearestValueFinder::FIND_LOWER |
||
19 | ); |
||
20 | $this->assertSame(0, $foundNearestLowerIndex); |
||
21 | |||
22 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
23 | 1337, |
||
24 | [1000, 2000, 3000], |
||
25 | SortedNumericArrayNearestValueFinder::FIND_HIGHER |
||
26 | ); |
||
27 | $this->assertSame(1, $foundNearestLowerIndex); |
||
28 | |||
29 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
30 | 2000, |
||
31 | [1000, 2000, 3000], |
||
32 | SortedNumericArrayNearestValueFinder::FIND_LOWER |
||
33 | ); |
||
34 | $this->assertSame(1, $foundNearestLowerIndex); |
||
35 | |||
36 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
37 | 1500, |
||
38 | [1000, 2000, 3000], |
||
39 | SortedNumericArrayNearestValueFinder::FIND_DEFAULT |
||
40 | ); |
||
41 | $this->assertSame(1, $foundNearestLowerIndex); |
||
42 | |||
43 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
44 | 1337, |
||
45 | [1000, 2000, 3000], |
||
46 | SortedNumericArrayNearestValueFinder::FIND_DEFAULT |
||
47 | ); |
||
48 | $this->assertSame(1, $foundNearestLowerIndex); |
||
49 | |||
50 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
51 | 4000, |
||
52 | [1000, 2000, 3000], |
||
53 | SortedNumericArrayNearestValueFinder::FIND_DEFAULT |
||
54 | ); |
||
55 | $this->assertSame(2, $foundNearestLowerIndex); |
||
56 | |||
57 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
58 | 4000, |
||
59 | [1000, 2000, 3000], |
||
60 | SortedNumericArrayNearestValueFinder::FIND_HIGHER |
||
61 | ); |
||
62 | $this->assertSame(2, $foundNearestLowerIndex); |
||
63 | |||
64 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
65 | 50, |
||
66 | [1000, 2000, 3000], |
||
67 | SortedNumericArrayNearestValueFinder::FIND_DEFAULT |
||
68 | ); |
||
69 | $this->assertSame(0, $foundNearestLowerIndex); |
||
70 | |||
71 | $foundNearestLowerIndex = SortedNumericArrayNearestValueFinder::findIndex( |
||
72 | 50, |
||
73 | [1000, 2000, 3000], |
||
74 | SortedNumericArrayNearestValueFinder::FIND_LOWER |
||
75 | ); |
||
76 | $this->assertSame(0, $foundNearestLowerIndex); |
||
77 | } |
||
112 |