Conditions | 8 |
Paths | 8 |
Total Lines | 51 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 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 testInsertAndSelect() : void |
||
33 | { |
||
34 | $value1 = 1.1; |
||
35 | $value2 = 77.99999999999; |
||
36 | $value3 = microtime(true); |
||
37 | |||
38 | $this->insert(1, $value1); |
||
39 | $this->insert(2, $value2); |
||
40 | $this->insert(3, $value3); |
||
41 | |||
42 | $result1 = $this->select(1); |
||
43 | $result2 = $this->select(2); |
||
44 | $result3 = $this->select(3); |
||
45 | |||
46 | if (is_string($result1)) { |
||
47 | $result1 = floatval($result1); |
||
48 | $result2 = floatval($result2); |
||
49 | $result3 = floatval($result3); |
||
50 | } |
||
51 | |||
52 | if ($result1 === false) { |
||
53 | $this->fail('Expected $result1 to not be false'); |
||
54 | |||
55 | return; |
||
56 | } |
||
57 | if ($result2 === false) { |
||
58 | $this->fail('Expected $result2 to not be false'); |
||
59 | |||
60 | return; |
||
61 | } |
||
62 | if ($result3 === false) { |
||
63 | $this->fail('Expected $result3 to not be false'); |
||
64 | |||
65 | return; |
||
66 | } |
||
67 | |||
68 | $diff1 = abs($result1 - $value1); |
||
69 | $diff2 = abs($result2 - $value2); |
||
70 | $diff3 = abs($result3 - $value3); |
||
71 | |||
72 | $this->assertLessThanOrEqual(0.0001, $diff1, sprintf('%f, %f, %f', $diff1, $result1, $value1)); |
||
73 | $this->assertLessThanOrEqual(0.0001, $diff2, sprintf('%f, %f, %f', $diff2, $result2, $value2)); |
||
74 | $this->assertLessThanOrEqual(0.0001, $diff3, sprintf('%f, %f, %f', $diff3, $result3, $value3)); |
||
75 | |||
76 | $result1 = $this->selectDouble($value1); |
||
77 | $result2 = $this->selectDouble($value2); |
||
78 | $result3 = $this->selectDouble($value3); |
||
79 | |||
80 | $this->assertSame(is_int($result1) ? 1 : '1', $result1); |
||
81 | $this->assertSame(is_int($result2) ? 2 : '2', $result2); |
||
82 | $this->assertSame(is_int($result3) ? 3 : '3', $result3); |
||
83 | } |
||
124 |